The shorthand to do so in bash or another console that supports it is: $ perl mycode.pl &> debug.txt
or the more explicit: $ perl mycode.pl 2>1 1> debug.txt
Both of these redirect streams STDERR and STDOUT to a file.
Also see: open 'STDERR', '>', './File' or die $!; and: open 'STDERR', '>', './File' or die $!;
Which would make it so the streams are rediected inside of the program rather than by the console.
Evan Carroll www.EvanCarroll.com
Comment on Re: Printing Warning Messages Into a File
No, that's broken in two ways. First, you are missing an ampersand... (which means your errors are going into the file ./1.) After you fix that, you'll still see the error. Pop quiz: Why?
Order matters. You have to redirect stdout before stderr... because otherwise stderr points to the old stdout while stdout points to the file.