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

I think that this is what you want.
sub bob { print 'bob'; } my $match = \&bob; my $nomatch = sub { print 'nob'; }; *alias = \&bob; for my $key (keys %main::) { if ($match == \&{$key}) { print "matched to $key\n"; } if ($nomatch == \&{$key}) { print "matched to $key\n"; } }
This will match `bob' and nothing else.

This will only find subroutines in the main package.

Update: Added Alias for completness.

-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: Finding the name of the target of a coderef
by adamk (Chaplain) on Apr 15, 2005 at 02:32 UTC
    Good start, now recurse down the entire symbol table, and you've got something that's a bit more useful.

    Oh, and it would return a list of many things that point to the that coderef.