SPUG: Tracing back to a calling sub
jimfl at tensegrity.net
Mon Jan 24 08:50:38 PST 2005
On Mon, 24 Jan 2005, Peter Darley wrote:
> I'm trying to figure out if there's a way for a sub to
> find out what sub called it?
Take a look at the second form of the 'caller' function. This should
get you at what you're looking for.
my $calling_sub = (caller(0));
There are situations where this won't quite get what you want, for
$foo = (caller(0));
will print "(eval)" in which case you'll have to increase the level
in the stack.
More information about the spug-list