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

Hi Monks, is there a function or package that can give a stack dump when an error occurs instead of a just one liner error?

Replies are listed 'Best First'.
Re: stack dump quest
by thedoe (Monk) on Feb 18, 2005 at 20:14 UTC

    You could try using the confess method in Carp.

    Also, CGI::Carp exists for use in CGI environments.

Re: stack dump quest
by holli (Abbot) on Feb 18, 2005 at 20:20 UTC
    This might give you an idea:
    use strict; use warnings; &a; sub a{ print "a"; &b } sub b{ print "b"; &c } sub c{ print "c"; die "arrgh at\n" . cstack() } sub cstack { my $i=1; my $stack=""; while ( my $s = (caller($i))[3] ) { $stack .= "$s\n" ; $i++; } return $stack; }
    see, caller


    holli, /regexed monk/
      this function is so cool! thanks
Re: stack dump quest
by TedYoung (Deacon) on Feb 18, 2005 at 22:34 UTC
    Based off thedoe's idea, but will give you a stack trace on all dies. BEGIN { $SIG{__DIE__} = sub { require Carp; Carp::confess("@_"); } }

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)