SPUG: Tracing back to a calling sub

Peter Darley pdarley at kinesis-cem.com
Mon Jan 24 08:34:46 PST 2005

	I'm trying to figure out if there's a way for a sub to find out what sub
called it?  The situation that I'm in is that I have a lot of generic subs,
such as one that takes a database query string and returns a hash of what
was loaded from the database.  When it fails, I just get an error from the
sub, but it's almost always a error in how I called the sub that caused
problems, and it can be hard to go back through my program and find which
sub called this sub incorrectly.
	So, basically what I want to be able to do is have something like:

sub MySub
	my (%Args) = @_;
	# Args: Query = The query to run the Lookup on

	if (! $Args{Query}) {die "A null querry was passed to MySub from


	And it would come up with something like
	"A null querry was passed to MySub from LookupUserInfo()!"

Peter Darley

More information about the spug-list mailing list