Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by Athanasius (Archbishop)
on Dec 12, 2012 at 08:05 UTC ( [id://1008468]=note: print w/replies, xml ) Need Help??


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

Here is one way:

#! perl use Modern::Perl; use List::Util qw( min ); my @vals = qw( 5 3 2 12 2 ); my @names = qw( Cat Bat Cow Dog Rat ); my $min_val = min @vals; my @indices = grep { $vals[$_] == $min_val } (0 .. $#vals); for (@indices) { printf "Lowest value: %d, index: %d, corresponding name: %s\n", $min_val, $_, $names[$_]; }

Output:

18:01 >perl 429_SoPW.pl Lowest value: 2, index: 2, corresponding name: Cow Lowest value: 2, index: 4, corresponding name: Rat 18:03 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: How can one call the lowest value of an array by reference?
by supriyoch_2008 (Monk) on Dec 12, 2012 at 10:24 UTC

    Hi Athanasius,

    Thanks for your quick reply. Your code has worked nicely. It has solved my problem.

    Regards,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found