Date: 2009nov25
Language: perl
Q. How can I make perl do a stack trace without any special packages?
A.
If you have no packages at all you can use this function:
sub show_call_stack() {
my($path, $line, $subr);
my $max_depth = 30;
my $i = 1;
print "--- Begin stack trace ---\n";
while ( (my @call_details = (caller($i++))) && ($i<$max_depth) ) {
print "$call_details[1] line $call_details[2] in function $call_details[3]\n";
}
print "--- End stack trace ---\n";
}
If you have Carp you can do:
use Carp qw(longmess);
print longmess();
I saw this on
http://www.perlmonks.org/?node_id=640319