Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by space_monk (Chaplain)
on Feb 21, 2013 at 15:36 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found