views:

89

answers:

1

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'.

+16  A: 

Use the caller function:

my $function = (caller(0))[3];
eugene y
+1 is there anything perl CAN'T do? :) Thanks!
David B