Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

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.


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;


In reply to Re: Logic problem by trantor
in thread Logic problem by toadi

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.