http://www.perlmonks.org?node_id=1019964


in reply to Is there a simple syntax to logically slice a hash?

map perhaps??
You can map one hash to another, but it is probably just as untidy as your example :-)
Something like these for the two examples you gave (I haven't got perl on this machine so please send me a private message and I'll fix it if wrong)
%hash2 = map { $_ => $hash{$_} } grep (/^cat/} keys %hash; # return empty list if ternary test fails.... %hash2 = map { $hash{$_} > 10 ? $_ => $hash{$_} : () } keys %hash;
A Monk aims to give answers to those who have none, and to learn from those who know more.