Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How can one call the lowest value of an array by reference?

by Kenosis (Priest)
on Dec 12, 2012 at 08:34 UTC ( #1008470=note: print w/ replies, xml ) Need Help??


in reply to How can one call the lowest value of an array by reference?

Here's another option:

use Modern::Perl; my @values = qw/5 3 2 12 2/; my @names = qw/Cat Bat Cow Dog Rat/; my %hash; push @{ $hash{ $values[$_] } }, $_ for 0 .. $#values; my $lowest = ( sort { $a <=> $b } keys %hash )[0]; say "Positions of Lowest Value ($lowest) = @{$hash{$lowest}}"; print 'The animal names are: '; print join ' ', map $names[$_], @{$hash{$lowest}};

Output:

Positions of Lowest Value (2) = 2 4 The animal names are: Cow Rat


Comment on Re: How can one call the lowest value of an array by reference?
Select or Download Code
Re^2: How can one call the lowest value of an array by reference?
by supriyoch_2008 (Scribe) on Dec 12, 2012 at 10:34 UTC

    Hi Kenosis,

    Thank you very much for your prompt reply and the code. It has worked well and has solved my problem.

    With Regards,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008470]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-07-03 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls