I may want to output info both to screen and sometime to a log file. Perl Cookbook recipe 13-9 offers one approach with Tie::Tee.
I also found a thread at http://perl.org.il/pipermail/perl/2003-June/002302.html where Mark Dominus offered:
{
my $teefile = "/tmp/teefile";
open my $fh, ">", $teefile or die $!;
open SAVE_STDERR, ">&STDERR" or die $!;
tie *STDERR, 'TEE', *SAVE_STDERR, $fh or die $!;
}
die "I like pie.n";
package TEE;
sub TIEHANDLE {
my $package = shift;
my @handles = @_;
bless @handles => $package;
}
sub PRINT {
my ($self, $data) = @_;
for my $fh (@$self) {
print $fh $data;
}
}