|
|
|
good chemistry is complicated, and a little bit messy -LW |
|
| PerlMonks |
How can one call the lowest value of an array by reference?by supriyoch_2008 (Scribe) |
| on Dec 12, 2012 at 07:43 UTC ( #1008463=perlquestion: print w/ replies, xml ) | Need Help?? |
|
supriyoch_2008 has asked for the
wisdom of the Perl Monks concerning the following question:
Hi PerlMonks, I am interested to find out the lowest value (2) from an array i.e. @values=qw/5 3 2 9 2/; and to find the corresponding animal name(s) associated with the lowest value (2) from the array @names=qw/Cat Bat Cow Dog Rat/. I have written the following script key1.pl to find the lowest value, the position of the lowest value and then to call the animal name by position. The cmd gives the correct result for position 4(Rat) and not for 2(Cow). Since the lowest value 2 appears at two positions in the array, the correct result should be Cow (position 2) and Rat (position 4). I am at my wit's end to get the correct result. May I request perlmonks to provide some suggestions. I know that %hash can be used but use of %hash appears a little complicated to me. In fact, I tried using %hash but failed. Then I have tried using the given approach i.e. lowest value->position-> calling the name. Here goes the code for key1.pl
I have got the following wrong results:
But the correct results should look like:
Back to
Seekers of Perl Wisdom
|
|