There are a couple of ways to do this, although I wouldn't recommend any of these for code that is actually supposed to do anything other than show up in some contest entry.
- Bless the anonymous sub into a package with the same name as the key. It still acts like an anonymous sub, but it has this extra package name. Use ref() to get the package name back.
- Enchant the code ref by blessing it into a package and overloading the stringification operator, sorta like I did in Re: Track the filename/line number of an anonymous coderef. That was just for giggles, so don't put that in any code that means anything to you.
- Create a reverse index and use the stringified value of the anonymous sub as the key. You can handle duplicate values by not allowing them or making the reverse index store multiple keys.
--
brian d foy <bdfoy@cpan.org>