note
ybiC
<p>
Here's one cross-platform way to simultaneously print to STDOUT and a filehandle.
</p>
<code>
# print messages to both console and logfile
sub PrintLogCon {
print @_;
print(LOG @_) or die "Error printing to $logfile: $!";
}
</code>
<p>
and you'd call it thusly:
</p>
<code>
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__
</code>
Phat props to mad monk [Petruchio] for showing me this a while back.
<br> cheers,
<br> Don
<br> <i>striving toward <a href="http://prometheus.frii.com/~gnat/yapc/2000-stages/">Perl Adept</a></i>
<br> <font size="-2">(it's pronounced "why-bick")</font>
<p>
<b>Update2: </b> consistant-ized scalar for logfile<br />
<b>Update1: </b> or use [cpan://IO::Tee] as shown by fine monk [jsprat].
</p>
208643
208643