in reply to Re: Teeing STDOUT and STDERR to files using filehandle references
in thread Teeing STDOUT and STDERR to files using filehandle references
In this case any attempt to print "foo\n" or print STDOUT "foo\n" will go to the logfile.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 +"; }
Or just use select:
In the second case print "foo\n" will print where you want but print STDOUT "foo\n" will still go to the real STDOUT.sub open_logfile { my $filename = shift; open FH, '> ' . $filename or die "Can't write to $filename: $!\n"; select FH; }
|
|---|
| 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 |