Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by Athanasius (Chancellor)
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,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019965]
help
Chatterbox?
[choroba]: a young lady didn't want to let us into a compartment she was sitting in, but we had valid tickets
[Discipulus]: and milano is our mitteleuropa part..
[choroba]: then an old man came who had a valid ticket to the same compartment and they fought
[Corion]: hippo: Yeah, I might take that one so I don't get out of London too late if it comes to that ;)
[choroba]: she called carabinieri, the train had to stop and we had to testify to them. But we didn't miss the plane in the end.
[karlgoethebier]: good morning *
[Discipulus]: miracle choroba! and unbelivalbe carabinieri understood you
[choroba]: They even sent me a letter whether I'd be willing to come to Milano to testify in the court
[choroba]: I replied with "yes" but the trial never happened
[Discipulus]: dont be so sure choroba.. 11 years is not too long for an Eatalian judgement

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-11-20 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (286 votes). Check out past polls.

    Notices?