webengr has asked for the wisdom of the Perl Monks concerning the following question:
This may have been asked (and answered) before, but I didn't run across it in the search tool.
My question is this: Is there a way that an anonymous sub stored as a hash value can have access to its associated key?
I am imagining something that would satisfy,
$h{'abc'} = sub { # # some sort of magic currently unknown to me # }; my $val = 'abc'; if ( $val eq $h{$val} ) { print "that works!",$/ }
At the moment this is just a curiosity for me, but if there is a way to do this it might come in handy sometime. If there's one thing that Perl has taught me, it's that I shouldn't jump to conclusions about what isn't possible.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can an anonymous sub in a hash value know its key?
by Anonymous Monk on Mar 17, 2005 at 10:25 UTC | |
by Tanktalus (Canon) on Mar 17, 2005 at 15:12 UTC | |
by webengr (Pilgrim) on Mar 17, 2005 at 21:42 UTC | |
|
Re: Can an anonymous sub in a hash value know its key?
by jdporter (Paladin) on Mar 17, 2005 at 06:42 UTC | |
|
Re: Can an anonymous sub in a hash value know its key?
by BrowserUk (Patriarch) on Mar 17, 2005 at 06:38 UTC | |
|
Re: Can an anonymous sub in a hash value know its key?
by brian_d_foy (Abbot) on Mar 17, 2005 at 08:53 UTC | |
|
Re: Can an anonymous sub in a hash value know its key?
by ikegami (Patriarch) on Mar 17, 2005 at 06:39 UTC | |
|
Re: Can an anonymous sub in a hash value know its key?
by NetWallah (Canon) on Mar 17, 2005 at 21:58 UTC |