Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Logic problem

by trantor (Chaplain)
on Nov 26, 2001 at 16:10 UTC ( #127527=note: print w/replies, xml ) Need Help??


in reply to Logic problem

Since you get to know the filename in the loop, you could simply store your lines in a string, then write it at once when you exit the loop. This is also much more efficient than opening the file each time for writing, also less prone to concurrency problems.

Example:

my $buffer = "first line\n"; foreach my $do (keys %doing) { # DO DB query for $do where fo $do can be serveral bodylines; $buffer .= $bodyline . "\n"; } $buffer .= "last line\n"; # now you know the file name open FILE, ">$name" or die "bla bla"; print FILE $buffer; close FILE;

-- TMTOWTDI

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2023-11-29 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?