perl -le 'sub func { print "In ".(caller(0))[3] }; $f=\&func; $f->();'


See also: perldoc -f caller
:-)

2010/12/5 Ray <[email protected]>

> $ perl -e 'sub function_name{print "This is a sub routine"}; my $d=
> \&f; $d->(); print $d'
> This is a sub routineCODE(0x1a6f6b0)
>
> 现在反过来,根据code reference,如何拿到function name?
> 具体问题来说
>
> my %hash = ('key1' => 1, "key2"=> \&filename::function)
> 现在知道这个hash,如何编程拿到“\&filename::function” 这个字符串。
> 注意: 要的是字符串
>
> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至 
> [email protected]<perlchina%[email protected]>
> 。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>
>

-- 
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

回复