14

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?

Community
  • 1
  • 1
Incognito
  • 1,883
  • 5
  • 21
  • 28
  • 2
    Dupe: http://stackoverflow.com/questions/738628 . Also, http://stackoverflow.com/questions/1877638 and http://stackoverflow.com/questions/971273 – mob Feb 22 '10 at 03:19

2 Answers2

24

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
  • 5,027
  • 1
  • 30
  • 33
12

Investigate the Carp::Always module.

tsee
  • 5,034
  • 1
  • 19
  • 27
  • 4
    `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 Feb 22 '10 at 17:03
  • 1
    I put `#!/c/Perl/bin/perl -MCarp::Always -w` as the first line in the script. And it said `Too late for "-MCarp::Always" option at ... line 1.` – Evgeni Sergeev Dec 27 '13 at 23:58