Thank you very much for your answers.Now I'm sure that solution 1 is the better solution.

As the author of a perl script my goal is it that it runs on a computer with much and less memory. So I do not know how much memory I have. But to give you numbers. sub_func1 writes about 50MB to the output file and sub_func2 writes about 150MB to the output file.

Do you think that holding about 200MB in memory is ok and then writing everything to the output file in one swoop? Or the other alternative would be to write first 50MB to the file and then 150MB. How many MB do you usually collect in memory if you want to use it on different computers?

Now to the reason why I want to move a line directly after building a part of the file. I'm computing a checksum which I know when sub_func1 finished. But the line with the checksum has to be at the beginning of the file and NOT at the end. My problem was that I thought that it is better to write everything directly to the file and that it is not ok to collect everything in memory. That's why I had the problem to move a line afterwards. If the memory solution is ok, then everything gets easier. Only main_func will then write to the file and the helper functions collect everything in memory.


In reply to Re^2: Design/Style question about writing to a file from different functions by Dirk80
in thread Design/Style question about writing to a file from different functions by Dirk80

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.