Hello Monks,

I have the following function calls:

main_func is opening a file and writing one line to it. Then main_func calls sub_func1 and after that sub_func2, which are in other modules. Afterwards main_func writes one more line into the file and then closes the file.

You see at the moment I open the file once in main_func and close it also in main_func. The function sub_func1 and sub_func2 do not open the file. They just get the file_handle of the file via a parameter and write to the file. Let's call this solution 1.

The other solution, let's call it solution 2, would be to open the file for writing in main_func, then write one line, close it. Then call sub_func1, open the file for appending, write some stuff into it, close it. Then sub_func2 is called. Opens the file for appending, writing some stuff, closing the file. Then main func opens the file for appending, writes one line into it, closes it.

What is the better solution? 1 or 2?

Now I have to add something to the current behaviour. After the call to sub_func1 I have to modify the file by moving one line to another position in the file. And then sub_func2 is called and everything goes on as before. I think that this kills solution 1. What would you suggest?

I'm just interested what is your meaning to this.

Thank you

Dirk


In reply to 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.