Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: grep for hash?

by poolpi (Hermit)
on Jul 07, 2009 at 12:38 UTC ( #777860=note: print w/replies, xml ) Need Help??

in reply to grep for hash?

Just with map:

use strict; use warnings; use Data::Dumper; my $orig = { 'foo' => 2, 'bar' => 4, 'boo' => 1, 'zar' => 5 }; my $dest; map { /oo/ and $dest->{$_} = $orig->{$_} } keys %$orig; print Dumper $dest; __END__ Output: $VAR1 = { 'boo' => 1, 'foo' => 2 };


'Ebry haffa hoe hab im tik a bush'. Jamaican proverb

Replies are listed 'Best First'.
Re^2: grep for hash?
by Fletch (Chancellor) on Jul 07, 2009 at 13:45 UTC

    Map in void context? Bleh. (See map versus for)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^2: grep for hash?
by Anonymous Monk on Jul 07, 2009 at 12:44 UTC
    Should be :D  /oo/ and $dest->{$_} = $orig->{$_} for keys %$orig;

      Written like it's said, "Copy each selected key":

      $dest->{$_} = $orig->{$_} for grep /oo/, keys %$orig;

      There's no need to twist one's mind to process the parent's expression.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://777860]
marioroy At a large firm, had to awaken a security guy a few times so that nobody would catch him sleeping.
marioroy On a large dairy farm, almost went off the road with a 10 wheeler from exhaustion. On the farm, almost went off the silo with a big tractor. At the Fransiscan monastery, almost slipped off the dome while painting it.
[marioroy]: In Saudi Arabia caught fire but didn't burn. I think angels exist.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-05-29 08:22 GMT
Find Nodes?
    Voting Booth?