开发者

How can I tell which subroutine I'm in?

开发者 https://www.devze.com 2023-01-11 15:43 出处:网络
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(); }

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


Use the caller function:

my $function = (caller(0))[3];
0

精彩评论

暂无评论...
验证码 换一张
取 消