Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by BrowserUk (Pope)
on Feb 21, 2013 at 15:49 UTC ( #1019970=note: print w/replies, xml ) Need Help??


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

I tend to do:

my %h2; /^cat/ and $h2{ $_ } = $h1{ $_ } for keys %h1;

Which might be seen as "cheating" as a one-liner; but it is often difficult to put the initialisation of a hash inline.

It is also quite more efficient than map and/or grep for larger hashes, by avoiding the creation of intermediate lists.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019970]
help
Chatterbox?
[FloydATC]: Is CPAN down?!?
[FloydATC]: I get a 404 for www.perl.com/CPAN
[choroba]: http://cpan.org
[FloydATC]: perl -MCPAN and the cpan command uses www.perl.com/CPAN
[FloydATC]: I was able to download and install what I needed manually, that's not the issue

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-01-24 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (256 votes). Check out past polls.

    Notices?