Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by Athanasius (Abbot)
on Feb 21, 2013 at 15:38 UTC ( #1019965=note: print w/ replies, xml ) Need Help??


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

You can take a functional approach and chain grep and map on a single line:

#! perl use strict; use warnings; use Data::Dump; my %h1 = (catastrophe => 1, cataclysm => 2, dogma => 3); my %h2 = map { $_ => $h1{$_} } grep { /^cat/ } keys %h1; dd %h2;

Output:

1:33 >perl 542_SoPW.pl ("catastrophe", 1, "cataclysm", 2) 1:37 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-07 19:17 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 (93 votes), past polls