Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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;


1:33 >perl ("catastrophe", 1, "cataclysm", 2) 1:37 >

Hope that helps,

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019965]
[Discipulus]: listen monks: do you think is possible to realize here at pm some kind of collaborative works? beyond ask & answer, i mean
[Tanktalus]: isn't that what github, sourceforge, gitlabs, etc., are for?
[Discipulus]: mmh.. i was no strictly thinking to programs; more on some new tutorials

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-09-22 21:15 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (269 votes). Check out past polls.