in reply to map and grep one-liner problem

Your specification is incomplete. What result do you want if the same key appears multiple times in your array? That is something that can't happen with a hash, but it can with your list-as-a-hash.

The complete result of a query for some key would have to be a list of matches. Using map() to generate such a result is reasonable, but let's look at your map again:

map{ /^$key/ and s/^$key//, $_ } grep( /^$key/, @ta))
For one, why do you check for the key with grep() and then again in the map block? One of the tests can go.

Secondly, you are using s/// to change the given array element into just the value. Apart from being ugly, this changes your array @ta, so it wouldn't work again the next time. Print @ta after your code has run to see what I mean. Simply extract the value using regex capture.

Third (as has been noted), you want a semicolon instead of comma to separate the statements in the map block. The map block is evaluated in list context, so the comma is a list operator and map will collect both values. That isn't what you want, and it's the reason you need to select the second element from the result ((...)[1]).

Here is one way to do what you want:

my @ta = ("a x", "b y", "c z", 'b yyy'); my $key = 'b'; my @values = map / (.*)/, grep /^$key /, @ta; print "@values\n";
If you only want the first hit, write
my ( $value) = map ...;
Anno