I would create two print statements. One goes to STDOUT and the other one goes into a global array. My logfile will be created from the global array. So I plan to create this logfile in case my script crashes/dies.

Are you printing the same thing to both STDOUT and the global array "log file", or does the log file get different information than STDOUT?

The normal unix way of doing things is to print output data to STDOUT (e.g. stuff that might be used by a downstream process in a pipeline) and to print log and/or error messages to STDERR, which is typically unbuffered by default.

If the idea is to handle a crash/die situation by making sure that all of stdout gets saved to a "log" file, unix users would just put a "tee [-a] log.file" command in the pipeline right after the perl script.

If the log data is different from stdout data, and the idea is to handle a crash/die by saving a trace of how far you got, just print log data to STDERR, and redirect stderr to a file on the command line, or open STDERR to a named file within your script.

But maybe I'm missing your point, because it wasn't clear from the OP what you're hoping to accomplish.


In reply to Re: creating log file question by graff
in thread creating log file question by EchoAngel

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.