in reply to Can an anonymous sub in a hash value know its key?

Not really. What happens if you associate the same sub with two keys?

my $code = sub { # # some sort of magic currently unknown to me # }; $h{'abc','xyz'} = ($code) x 2;

The only way I can see is if you embed a self-referential closure to the coderef within the sub and then grep the hash looking for a key with that coderef as it's value.

You could probably use someting in the B::* set of modules to walk the optree and locate yourself (you own coderef) from within the sub, but you're still back to searching the hash for keys with that as a value.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?