Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: redirect all output

by ihb (Deacon)
on Apr 28, 2005 at 14:35 UTC ( [id://452309] : note . print w/replies, xml ) Need Help??


in reply to redirect all output

You can duplicate STDOUT and then reopen STDOUT to something else.

open my $stdout, '>&STDOUT' or die $!; open STDOUT, '>', $file or die $!;
Now everything printed to STDOUT ends up in the file given by $file. If you want to print to the original STDOUT you can do that by doing print $stdout 'hello';.

See perlopentut for more on this.

ihb

See perltoc if you don't know which perldoc to read!