perlpreben has asked for the wisdom of the Perl Monks concerning the following question:

I need to do some debugging, and would really like to know how to redirect all "print"/warnings/errors etc to a file, insted of showing up on screen. Is this easy to do?

Replies are listed 'Best First'.
Re: Redirect STDOUT to textfile?
by Anonymous Monk on Dec 06, 2010 at 01:54 UTC
    If the shell redirection method isn't suitable (eg, running in a CGI script, or envoked in some other way you can't control), there are other options.
    • open(STDERR, '>>', $filename) or die "can't open log $filename: $!"
    • PerlIO::Util or PerlIO::tee to copy, like STDERR->push_layer(tee => \$filehandle);
Re: Redirect STDOUT to textfile?
by Anonymous Monk on Dec 05, 2010 at 23:54 UTC
    Yes
    perl foo.pl 1>1 2>2 perl foo.pl >file 2>&1
Re: Redirect STDOUT to textfile?
by eff_i_g (Curate) on Dec 06, 2010 at 15:32 UTC
Re: Redirect STDOUT to textfile?
by doug (Pilgrim) on Dec 06, 2010 at 21:47 UTC

    File manipulation starts with the open() command, so start by reading the documentation

    perldoc -f open

    and then search down for the words

    Here is a script that saves, redirects, and restores "STDOUT" and "STDERR" using various methods: