Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: find minimum in list

by Limbic~Region (Chancellor)
on Feb 10, 2004 at 14:02 UTC ( [id://327919]=note: print w/replies, xml ) Need Help??


in reply to find minimum in list

Anonymous Monk,
While there is a module that has just the function you are looking for, your second question leads me to offer the "low water mark" solution.
#!/usr/bin/perl use strict; use warnings; my @list = qw(4 78 3 89 4 1000 5); my %minimum; for my $index ( 0 .. $#list ) { @minimum{ qw(index min) } = ($index , $list[$index]) if ! %minimum; if ( $list[$index] < $minimum{min} ) { @minimum{ qw(index min) } = ($index , $list[$index]); } } print "The index of the smallest number is : $minimum{index}\n"; print "The valud of the smallest number is : $minimum{min}\n";
Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found