in reply to map and grep one-liner problem

I don't think using /^$key/ is a good idea because you want an exact match so that a key of "b" doesn't find an entry of "bbking" => "legend". A test for string equality would be safer.

use strict; use warnings; my @ta = (q{a x}, q{b y}, q{c z}); my $key = q{b}; print qq{key = $key, value is @{[getValue($key)]}\n}; sub getValue { my $key = shift; return map { $_->[1] } grep { $_->[0] eq $key } map { [ split ] } @ta; }

The output is

key = b, value is y

I hope this is of use.

Cheers,

JohnGG

Update: Thinking about it, you could do most of the work inside the print statement, getting rid of the subroutine

use strict; use warnings; my @ta = (q{a x}, q{b y}, q{c z}); my $key = q{b}; print qq{key = $key, value is @{ [ map { $_->[1] } grep { $_->[0] eq $key } map { [ split ] } @ta ] }\n};

This produces the same output as the first version.