in reply to mapping through filehandles
There's this, or the more fully featured IO::Tee module on CPAN.
package TeeHandle; use Carp; use Symbol (); sub TIEHANDLE { my( $class, $file, $dst_handle ) = @_; my $handle = Symbol::gensym; # Make a filehandle name my $true_handle = Symbol::gensym; open( $true_handle, ">&$dst_handle" ) or croak "Can't dup handle '$dst_handle': $!"; open( $handle, ">$file" ) or croak "Can't create '$file': $!"; return bless { handle => $handle, true => $true_handle }, $class; } sub PRINT { my $self = shift; for (@_) { print {$self->{handle}} "$_"; print {$self->{true}} "$_"; } } 1; __END__ package main; use Carp; use Symbol (); tie *STDOUT => 'TeeHandle', "out", 'STDOUT'; tie *STDERR => 'TeeHandle', "err", 'STDERR'; print "Testing . . .\n"; print STDERR "This goes to STDERR\n"; CORE::warn "Where do I go?\n"; ## This doesn't work. system '/bin/sh', '-c', 'echo "Testing if it\'s propigated" 1>&2'; exit 0;
|
|---|