Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
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 browsing the Monastery: (7)
As of 2014-04-19 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls