SPUG: Tracing back to a calling sub

Peter Darley pdarley at kinesis-cem.com
Mon Jan 24 09:04:53 PST 2005

	That's exactly what I'm looking for.
	I can write a sub that uses caller(2) that I can use to format the
information in a standard way, and then use:

	die "A null query was passed to MySub from " . GetCaller() . "!"

	Thanks for your help!

Peter Darley

-----Original Message-----
From: Kirby Krueger [mailto:kirbyk at gmail.com]
Sent: Monday, January 24, 2005 8:45 AM
To: Peter Darley
Subject: Re: SPUG: Tracing back to a calling sub

Check out perldoc -f caller.  Is this what you're looking for?

-- Kirby

On Mon, 24 Jan 2005 08:34:46 -0800, Peter Darley
<pdarley at kinesis-cem.com> wrote:
> Folks,
>         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
> 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
> $Calling_Sub!"}
>         ...
> }
>         And it would come up with something like
>         "A null querry was passed to MySub from LookupUserInfo()!"
> Thanks,
> Peter Darley
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
>     WEB PAGE: http://seattleperl.org/

More information about the spug-list mailing list