in reply to Re: Teeing STDOUT and STDERR to files using filehandle references
in thread Teeing STDOUT and STDERR to files using filehandle references

How about dupping the filehandle:
sub open_logfile { my $filename = shift; open STDOUTBACK, '>&STDOUT' or die "Can't dup STDOUT\n"; open STDOUT, '> ' . $filename or die "can't write to $filename: $!\n +"; }
In this case any attempt to print "foo\n" or print STDOUT "foo\n" will go to the logfile.

Or just use select:

sub open_logfile { my $filename = shift; open FH, '> ' . $filename or die "Can't write to $filename: $!\n"; select FH; }
In the second case print "foo\n" will print where you want but print STDOUT "foo\n" will still go to the real STDOUT.

Replies are listed 'Best First'.
Re: Re: Re: Teeing STDOUT and STDERR to files using filehandle references
by isotope (Deacon) on Dec 18, 2000 at 22:11 UTC
    This is correct, but it's not the solution to my problem... I'm redirecting to existing filehandles, not opening new files.

    --isotope
    http://www.skylab.org/~isotope/