in reply to Re: chooseDirectory set Default
in thread chooseDirectory set Default

thx

Replies are listed 'Best First'.
Re^3: chooseDirectory set Default
by olus (Curate) on Jul 11, 2008 at 22:23 UTC

    Sure mate. But this time you gotta promise you will read open's docs :).

    First point: when you read the file, and since you are adding more lines, you have to get all those lines. Also, you are appending a new line to the end of each conf variable, so there is the need to chomp that new line.

    if (-f $file) { open CONF, "<$file"; my @contents = <CONF>; close CONF; foreach $content (@contents) { my @config = split /-/,$content; if ($content =~ /DEFAULT_IN/) { $default_in = $config[1]; chomp($default_in); } elsif ($content =~ /DEFAULT_OUT/) { $default_out = $config[1]; chomp($default_out); } } }

    Second point: Writing the info back to the file. I don't know what those browse methods are, but if you need to write in two separate steps, then you'll have to write all the info both times.

    print CONF "DEFAULT_IN-$def_path\nDEFAULT_OUT-$def_path_out\n";

    As a side note, you should look for a way of being able to write only if any of the paths actually changed.

    if( ($def_path ne $default_in) || ($def_path_out ne $default_out) ) { # at least one of the values changed, write both }

    update lil_v updated his node, so now this doesn't make much sense.