Gtforce has asked for the wisdom of the Perl Monks concerning the following question:
I have an @array where a=stock and b=value.
a1 b1 a2 b2 a3 b3 a5 b5 a4 b4
My objective is to find the stock in the array and get its corresponding value for further printing or processing. When I use something like this:
my $stockval = grep{/a2/} @array;I get a '1' in my $stockval. I'm guessing that I'm only being told about whether a2 exists in the array or not. What should I be doing to get a2's corresponding value b2 into my $stockval? I realize that this probably a very rookie question (am new to perl). Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: search and return values from an array
by Eily (Monsignor) on Feb 14, 2018 at 16:54 UTC | |
by Gtforce (Sexton) on Feb 14, 2018 at 18:43 UTC | |
|
Re: search and return values from an array
by thanos1983 (Parson) on Feb 14, 2018 at 16:45 UTC | |
by Gtforce (Sexton) on Feb 14, 2018 at 18:39 UTC | |
by thanos1983 (Parson) on Feb 15, 2018 at 12:06 UTC | |
|
Re: search and return values from an array
by Anonymous Monk on Feb 15, 2018 at 09:27 UTC |