Sometimes, in an automated process, we get surprised with some output that we, um, didn't properly trap. As in, "this could never fail, so..." Famous last words. So, as a self-diagnostic aid, I figured I'd just replace my script with a wrapper script that redirected stdout and stderr both to some file on the shared disk that everything else is put into. That way, when I'm looking at everything else that is generated, I can see any error/warning messages that perl may put out which may help explain why something didn't occur that I thought it should.

Then I realised that the output directory is extremely variable. And that I won't know it until well after the first text is printed out. "Simple," says I. "I'll just use another module that delays output until I tell it where to output, and store it until then." Unfortunately, I can't seem to find IO::File::Delayed on CPAN. Perhaps this isn't such a common requirement afterall.

So I'm thinking of creating something derived from IO::Handle where, if a file is given, we open and write to it. If no file is given, we just append any text to an internal scalar (or push on an internal array?). Once a file name is given, we open and write out all our buffered data. Maybe a "pause" or "stop" function which closes the file, but allows us to continue writing to the filehandle.

Two questions: first, did I miss something on CPAN or the like? Second, if not, does this sound reasonable?

Thanks,


In reply to Delayed-write object/module by Tanktalus

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.