in reply to Re: map and grep (but for hashes)
in thread map and grep (but for hashes)
It would depend on what you are trying to do, probably. The one thing I've noticed is that usually I don't actually need a new hash: I just need to know which values are in the new hash.
My other trick would be to split it into two lines, and use a hash slice:
@new_keys = grep { $hash{$_} == $condition } keys %hash; @new_hash{@new_keys} = @hash{@new_keys};
I'm sure there are other ways, but that's fairly short and clear.
(Fixed: Thanks lostjimmy.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: map and grep (but for hashes)
by lostjimmy (Chaplain) on Jan 30, 2009 at 19:48 UTC | |
by zerohero (Monk) on Jan 30, 2009 at 20:13 UTC | |
by zerohero (Monk) on Jan 30, 2009 at 20:32 UTC | |
|
Re^3: map and grep (but for hashes)
by zerohero (Monk) on Jan 30, 2009 at 20:17 UTC | |
by DStaal (Chaplain) on Jan 30, 2009 at 20:39 UTC |