in reply to map and grep one-liner problem
TIMTOWDI (I had some time to kill :-)
I assume your 'keys' are unique.*
my @ta = ( 'a x', 'b y', 'c z' ); my $key = 'b'; printf "key=%s, value=%s\n", map split, grep { ! index $_, $key . ' ' +} @ta; printf "key=%s, value=%s\n", $key, ${{ map split, @ta }}{$key};
* If not, the first snippet will select the first hit, while the second will give you the last hit.
Update: I could of course have simplified the second snippet further:
printf "key=%s, value=%s\n", $key, { map split, @ta }->{$key};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map and grep one-liner problem
by jeanluca (Deacon) on Mar 14, 2007 at 14:18 UTC | |
by Not_a_Number (Prior) on Mar 14, 2007 at 14:38 UTC | |
by jeanluca (Deacon) on Mar 14, 2007 at 16:48 UTC |