Tanktalus has asked for the wisdom of the Perl Monks concerning the following question:
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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Delayed-write object/module
by BrowserUk (Patriarch) on Feb 14, 2006 at 05:13 UTC | |
|
Re: Delayed-write object/module
by davidrw (Prior) on Feb 14, 2006 at 02:01 UTC | |
by Tanktalus (Canon) on Feb 14, 2006 at 04:28 UTC |