jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
This works great, but for some reason I don't think I've the best solution, because I have to add (...)[1], around the one-liner in order to get the 'value', which doesn't feel right. Element [0] contains a 1.#! /usr/bin/perl -lw # use strict ; my $key = "b" ; printf "key=%s, value is %s\n", $key, get_value($key) ; sub get_value { my $key = shift ; my @ta = ("a x", "b y", "c z") ; # test array return (map{ /^$key/ and s/^$key//, $_ } grep( /^$key/, @ta))[1] ; }
it doesn't work verywell anymore, I only added a print statement ?map{ /^$key/ and s/^$key// and print "val=$_\n", $_ }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: map and grep one-liner problem
by johngg (Canon) on Mar 14, 2007 at 11:45 UTC | |
|
Re: map and grep one-liner problem
by shmem (Chancellor) on Mar 14, 2007 at 12:04 UTC | |
|
Re: map and grep one-liner problem
by Anno (Deacon) on Mar 14, 2007 at 12:45 UTC | |
|
Re: map and grep one-liner problem
by Not_a_Number (Prior) on Mar 14, 2007 at 13:55 UTC | |
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 | |
|
Re: map and grep one-liner problem
by jeanluca (Deacon) on Mar 14, 2007 at 13:13 UTC |