Is is possible to determine the "name" by which name a reference to sub is called?
There are two ways I can think of, neither of which are (IMHO) elegant and both of which are kludges since you're not really getting the calling info from the reference, but rather by how you defined them.
The first uses wrappers (anonymous or otherwise)...
$divesub = sub { somesub('divesub') }; $raisesub = sub { somesub('raisesub') }; sub somesub { if ( $_[0] eq "divesub") { &dive; } else { &surface; } }
... while the second would be to rename your sub to the magical AUTOLOAD and point each reference to a non-existant sub so that it got ran instead ...
$divesub = \&divesub; $raisesub = \&raisesub; sub AUTOLOAD { (my $sub = $AUTOLOAD) =~ s/.*:://; if ( $sub eq "divesub" ) { &dive; } else { &surface; } }
--k.
In reply to Re: sub calling name
by Kanji
in thread sub calling name
by Dogma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |