in reply to Debugging My Perl

perl script.pl 1>out 2>&1
redirects STDOUT (1) and STDERR (2) to the file out.

I am going to assume you are on Win32 in which case redirection of STDERR does not work. On old versions of Win32 redirection of STDERR does not work. Perhaps the easiest way to see all your errors is simply to increase the screen buffer of the (DOS) terminal window you are using to run your perl script. To increase the buffer, do this in a DOS window:

Now you will have a scroll bar on the RHS of the DOS window and will be able to scroll back through hundreds of lines.

Update

Fixed incorrect statement as noted by BrowserUk and AM and changed syntax to one that works on Win32 and with Bash.

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Debugging My Perl
by sintadil (Pilgrim) on Sep 06, 2004 at 10:57 UTC

    If you were on *nix you would probably already know how to do redirection like perl -e ' die' 2&> out where the 2&>out redirects STDERR (and STDOUT) to the file out.

    You forgot to mention that this works with Bourne shells only. Please don't assume that someone is using a Bourne shell -- or that they even have one. Some of us, in fact, despise Bourne shells, and avoid them at all cost.

      Next you're going to tell me you use emacs, not vi..... ;-)

      cheers

      tachyon

        Actually, I avoid all things EMACS. But the less I state my opinions on EMACS in general and GNU things in particular the better, considering the nature of such opinions. :)

Re^2: Debugging My Perl
by DrHyde (Prior) on Sep 06, 2004 at 09:25 UTC
    Another way would be to install die() and warn() handlers in %SIG to log to a file. Localise them to just the bit of code that you're interested in:
    local $SIG{__DIE__} = sub { open LOGFILE, '>>logfile'; print LOGFILE 'die: ', @_; die("Died, errors logged to file\n"); } local $SIG{__WARN__} = sub { open LOGFILE, '>>logfile'; print LOGFILE 'warn: ', @_; close LOGFILE; }
    It may also be useful to log a timestamp for all die()s and warn()s, and spit out stack traces.
Re^2: Debugging My Perl
by BrowserUk (Patriarch) on Sep 06, 2004 at 14:01 UTC
    I am going to assume you are on Win32 in which case redirection of STDERR does not work...

    Really?

    P:\test>perl -le"warn 'via STDERR'; print 'via STDOUT';" 1>junk 2>&1 P:\test>type junk via STDERR at -e line 1. via STDOUT P:\test>

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re^2: Debugging My Perl
by Anonymous Monk on Sep 06, 2004 at 11:45 UTC
    Apologies if I've misunderstood, but redirecting STDERR works fine on WinXP:

    perl script.pl 1>stdout.txt 2>stderr.txt
Re^2: Debugging My Perl
by Spidy (Chaplain) on Sep 06, 2004 at 04:45 UTC
    ...Hmmm. I'm using windows 98. And while looking at the DOS title bar, I don't see a 'defaults'. Any other ideas?