Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Is there a simple syntax to logically slice a hash?

by space_monk (Chaplain)
on Feb 21, 2013 at 15:36 UTC ( #1019964=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019964]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2016-10-24 03:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.