Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: finding highest number

by thinker (Parson)
on Dec 05, 2002 at 13:03 UTC ( [id://217747]=note: print w/replies, xml ) Need Help??


in reply to finding highest number

Hi,

There is a flaw in your logic. A corrected version is here.
Notice how the List::Util::max function does what you want.
#!/usr/bin/perl -w use strict; use List::Util; #for the max function my @numbers = qw( 10 4 7 2 5 8 1 3 11); my $highest=$numbers[0]; # Initialise this for case of all negatives for (my $i = 1; $i < @numbers; $i++) { if ($numbers[$i] > $highest) { #compare to the previous hig +hest $highest = $numbers[$i]; } } print "\$highest is $highest\n"; #now use List::Util::max print "Max is ", List::Util::max(@numbers),"\n";
hope this helps

thinker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-24 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found