in reply to Finding the name of the target of a coderef

You mean something like this?
#!/usr/bin/perl use strict; use warnings; my $anon = sub { return "foo " . "bar" }; my $retVal = &$anon; print $retVal ;

update
Ah i did not understand the question that way. After rereading i even thought more like the following, where you can get the sub (a) since it's the key of a blessed hash, with the sub inside...
well, now i have to think about it...
#!/usr/bin/perl use strict; use warnings; my $anon = bar->new; my $retVal = &{$anon->{a}}; print $retVal ; package bar; sub new{ my $self = bless{}; $self->{a} = sub { return "bar"; } ; $self; }
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Replies are listed 'Best First'.
Re^2: Finding the name of the target of a coderef
by moot (Chaplain) on Apr 14, 2005 at 22:41 UTC
    I think the OP was more interested in this:
    sub foo { # do groovy things here } my $coderef = \&foo; my $method_name = mythical_coderef_name_fetcher($coderef); print $method_name; # output is 'foo'
    AFAIK there's no way to do this. Any takers?
Re^2: Finding the name of the target of a coderef
by Forsaken (Friar) on Apr 14, 2005 at 22:42 UTC
    code example moved to original post for ease of reading.