x:\perl\site\lib\My\Tee.pm
####
package My::Tee;
use Tie::Handle;
our @ISA = qw[ Tie::Handle ];
sub TIEHANDLE {
die "Usage: tie *STDxxx, 'My::Tee', 'logfilepath'"
unless @_ == 2;
open my $std, '>', 'CON'
or die "Couldn't reopen STDxxx : $!"
and return;
my( $flush, $old ) = ( $|, select( $std ) );
$| = $flush; select( $old );
open my $log, '>', $_[1]
or die "Couldn't open $_[1] for output: $!"
and return;
bless { log => $log, stdout => $std }, $_[0];
}
sub PRINT {
my $self = shift;
print { $self->{ log } } @_;
print { $self->{ stdout } } @_;
}
sub PRINTF {
my $self = shift;
printf { $self->{ log } } @_;
printf { $self->{ stdout } } @_;
}
1;
####
tie *STDxxx, 'My::Tee', '\path\to\logfile';