### How do I find the biggest number in an array of numbers.

 on Jan 27, 2001 at 02:46 UTC Need Help??
Contributed by Anonymous Monk on Jan 27, 2001 at 02:46 UTC
Q&A  > arrays

#### Description:

 Answer: How do I find the biggest number in an array of numbers.contributed by Fastolfe ```use List::Util 'max'; ... my \$max = max( @list ); [download]``` Answer: How do I find the biggest number in an array of numbers.contributed by flocto ```my \$max = (sort { \$b <=> \$a } @array)[0]; [download]``` Answer: How do I find the biggest number in an array of numbers.contributed by MrNobo1024 ```my \$max = \$list[0]; \$_ > \$max and \$max = \$_ for @list; [download]``` Answer: How do I find the biggest number in an array of numbers.contributed by lemming See finding min and max of array recursivly. (Nevermind the recursive bit.) Answer: How do I find the biggest number in an array of numbers.contributed by Beatnik ```@list = sort { \$a <=> \$b } @list; \$max = \$list[\$#list]; [download]``` Answer: How do I find the biggest number in an array of numbers.contributed by Skeeve ```my @data = (1, 30, 4, 5, 12, -12, 4.1, 18,20, 2, 0 ,4, 36, 0, 8, 15, 4 +2, 4711, 0xdead, 0xbeef); my \$max = \$data[0]; \$max= \$_>\$max ? \$_ : \$max foreach (@data); print \$max,"\n" [download]``` Answer: How do I find the biggest number in an array of numbers.contributed by salva If what you need is not just the biggest element but the N biggest elements, you can use Sort::Key::Top: ```use Sort::Key::Top qw(rntop ntop); my \$n = 5; my @data = (1, 30, 4, 5, 12, -12, 4.1, ...); my @min_n = ntop \$n => @data; my @max_n = rntop \$n => @data; [download]```

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2018-01-23 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (244 votes). Check out past polls.

Notices?