Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: chooseDirectory set Default

by olus (Curate)
on Jul 11, 2008 at 22:23 UTC ( [id://697106]=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://697106]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-24 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found