Reputation: 29968
Is there a way to get the name of the enclosing subroutine of a piece of perl code? For example:
sub foo { print where_am_i(); }
will output 'foo'.
'foo'
Upvotes: 5
Views: 231
Reputation: 149726
Use the caller function:
my $function = (caller(0))[3];
Upvotes: 17