#!/usr/bin/perl sub foo { print "In foo\n"; } sub findit { my $ref = shift; local(*alias); *stash = *{"main::"}; while ((my $varname, my $globvalue) = each %stash){ next if $varname eq "alias"; *alias = $globvalue; if (defined(&alias)){ if ($ref eq \&alias){ return $varname; } } } } my $fref = \&foo; my $fname = findit($fref); print "ref points to $fname\n";
bryan@web ~$ ./ns ref points to foo bryan@web ~$
In reply to Re: Finding the name of the target of a coderef
by bschmer
in thread Finding the name of the target of a coderef
by Forsaken
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |