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.


In reply to Re^3: chooseDirectory set Default by olus
in thread chooseDirectory set Default by lil_v

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.