c has asked for the wisdom of the Perl Monks concerning the following question:
sub add { open FH, ">>$file" or die "Cant open config file $!\n"; &lock(*FH); print FH "zone \"$formdata{domain}\" in \{\n\ttype slave\;\n\tfile\" +$client\/ db.$formdata{domain}\"\;\n\tallow-query \{ any\; \}\; \}\;\n\n"; &unlock(*FH); close FH; open FH, "$file" or die "Could not open $file : $!\n"; &lock(*FH); $/ = "\;\n\n"; my @array = <FH>; @array = sort @array; &unlock(*FH); close FH; open FH, ">$file"; &lock(*FH); print FH @array; &unlock(*FH); close FH; $/ = "\n"; }
I guess I have two main questions. First, do I need to lock and unlock the files with each open statement? or can I do this once at the beginning and then unlock at the end of the three procedures? I read over flock but didnt get a good feel of whether or not the statement could include multiple open and closes before an unlock statement was set.
And finally, does this process really need to have "$file" ">>$file" and ">$file"? I can't come up with other methods that work, so I offer it up for your advice.
humbly -c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opening the same file over and over. Shorter way to do this?
by Masem (Monsignor) on Aug 01, 2001 at 18:06 UTC | |
|
Re: Opening the same file over and over. Shorter way to do this?
by suaveant (Parson) on Aug 01, 2001 at 18:27 UTC | |
|
Re: Opening the same file over and over. Shorter way to do this?
by Cubes (Pilgrim) on Aug 01, 2001 at 18:17 UTC | |
|
Re: Opening the same file over and over. Shorter way to do this?
by dga (Hermit) on Aug 02, 2001 at 01:16 UTC |