in reply to Re^2: Porting Perl 5.6 to Perl 5.8 issue with self-tie
in thread Porting Perl 5.6 to Perl 5.8 issue with self-tie
The problem came in when I tried to do the same with STDERR. In this case all the output from STDERR disappeared. If I swapped the STDERR and STDOUT ties done in this manner, I would then get STDERR output and not STDOUT.That's because you are essentially doing:
where FOO and BAR have independent file pointers into the same file. If you want to share a logfile between two handles, use >> to force all writes to append at the end, or open the file outside the tie handler and pass its glob to your logger.perl -we'open FOO, "> baz"; open BAR, "> baz"; print FOO "one\n"; prin +t BAR "one\n";'
This works for me:
use InstallerHandleTie; my $gfh = *STDOUT; my $geh = *STDERR; foreach my $outfile (qw/log1 log2/) { open my $outfh, ">", $outfile or die "nope: $!"; local *STDOUT; local *STDERR; tie *STDOUT, 'InstallerHandleTie', $outfh, $gfh; tie *STDERR, 'InstallerHandleTie', $outfh, $geh; print "Writing to $outfile\n"; warn "Writing warning to $outfile\n"; untie *STDOUT; untie *STDERR; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Porting Perl 5.6 to Perl 5.8 issue with self-tie
by fwashbur (Sexton) on Dec 13, 2006 at 01:01 UTC |