Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.


Comment on Re: Is there a simple syntax to logically slice a hash?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2015-07-31 12:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (277 votes), past polls