rob_au has asked for the wisdom of the Perl Monks concerning the following question:
sub write_logfile ($$) { use Time::HiRes 'time'; my ($file, $message) = @_; chomp($message); if (defined($file)) { open OLDERR, ">&STDERR"; open STDERR, ">>$file"; flock STDERR, 8; print OLDERR ""; }; print STDERR time, " [", $$, "] ", $message, "\n"; if (defined($file)) { close STDERR; open STDERR, ">&OLDERR"; }; };
The duplication and restoration of STDERR however seems messy and I'm wondering if TAMBWTDI (there's a much better way to do it).
Note: The print OLDERR ""; line is there to prevent the 'Name "main::OLDERR" used only once: possible typo at blah.perl line 162.' error otherwise generated under -w as per melguin's node here.
Ooohhh, Rob no beer function well without!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cleaner redirection of STDERR
by trantor (Chaplain) on Sep 23, 2001 at 10:59 UTC | |
Re: Cleaner redirection of STDERR
by RhetTbull (Curate) on Sep 24, 2001 at 07:58 UTC | |
by tilly (Archbishop) on Sep 24, 2001 at 08:33 UTC | |
Re: Cleaner redirection of STDERR
by CubicSpline (Friar) on Sep 23, 2001 at 16:38 UTC | |
by blakem (Monsignor) on Sep 23, 2001 at 16:44 UTC |