views:

231

answers:

2

Possible Duplicate:
How do I force a stack backtrace for all fatal errors in Perl?

One of the things I like about Python, is that when a script exits because of an error, it spits out a traceback. I'm wondering is there anyway of getting a Perl to do this as well?

+10  A: 

Add this to the top of your script:

use Carp 'verbose';
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };

It will create a stack trace on all fatal errors.

Gavin Brock
You could also make that `$SIG{__DIE__} = \`
Leon Timmermans
+5  A: 

Investigate the Carp::Always module.

tsee
`Carp::Always` is a much better method than messing about with sigdie because you can enable it from the command line. `perl -MCarp::Always my_script` Very, very nice.
daotoad