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")