Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Partial extractions on hashes

by busunsl (Vicar)
on May 11, 2001 at 16:23 UTC ( [id://79684]=note: print w/replies, xml ) Need Help??


in reply to Partial extractions on hashes

For a partial match on values in a hash try this:
%hash = ('k1' => 'abc', 'k2' => 'def', 'k3' => '123abcdef456'); @array = map { $_->[1] } grep { $_->[1] =~ /abc/ } map { [$_, $hash{$_ +}] } keys %hash); foreach (@array) { print $hash{$_}, "\n"; }

Replies are listed 'Best First'.
(tye)Re: Partial extractions on hashes
by tye (Sage) on May 12, 2001 at 01:57 UTC

    You can shorten that quite a bit:

    %hash = ('k1' => 'abc', 'k2' => 'def', 'k3' => '123abcdef456'); @array = map $hash{$_} =~ /abc/ ? $_ : (), keys %hash; foreach (@array) { print "$_: $hash{$_}\n"; }

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found