Dave's Brain

Browse - programming tips - perl show call stack

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();

From http://www.perlmonks.org/?node_id=640319
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.