in reply to printing to STDOUT and a Logfile
Here's one cross-platform way to simultaneously print to STDOUT and a filehandle.
# print messages to both console and logfile sub PrintLogCon { print @_; print(LOG @_) or die "Error printing to $logfile: $!"; }
and you'd call it thusly:
Phat props to mad monk Petruchio for showing me this a while back.use warnings; use strict; open(LOG, ">$logfile") or die "Error opening $logfile: $!"; ... ... ... do->stuff; do->it(again) or PrintLogCon("Error: $!"); do->stuff(more); ... ... ... close LOG or die "Error closing $logfile: $!"; __END__
cheers,
Don
striving toward Perl Adept
(it's pronounced "why-bick")
Update2: consistant-ized scalar for logfile
Update1: or use IO::Tee as shown by fine monk jsprat.
|
---|
In Section
Seekers of Perl Wisdom