Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Err, I did say it was untested didn't I? There are two errors related to the hash. The second one is that the return statement needs to be changed to:
to return the value instead of the key. The first problem is as you noticed, the hash needs to be passed to the sub, but it needs to be passed by reference because of the way the code in the sub works:
The pass by reference is an optimisation to save passing all the keys and values of the hash in a list which is what would happen otherwise. Note that the point of passing the hash at all is to avoid treating it as a global variable which is generally a "bad thing"™ (although this is such a small program it's not an issue except as a style thing).
True laziness is hard work
In reply to Re^3: grep keys in hash and retrieve values
by GrandFather
|
|