--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "srinivas reddy"
<reddysrinivas.k...> wrote:
>
> Hi,
>
> Would you please let me know the efficient way (different ways) to
get the
> max or nth largest element in an array
>
> --
> -SrINIvAS ReDdY....
>
>
> [Non-text portions of this message have been removed]
>
Hi,
Well to be honest this is an algorithm question. But one of them is
using built in functions or a loop and a temp value or binary search. But note that perl does have his own order for arrays so it's good
practice to order the array first. Although this only applies to
hashes... Well never mind
>>>>> "srinivas" == srinivas reddy < reddysrinivas.k%40gmail.com">reddysrinivas.kgmail.com> writes:
srinivas> Would you please let me know the efficient way (different ways) to get the
srinivas> max or nth largest element in an array
use List::Util;
my $max = max(some_array);
That's the most efficient, because it's implemented in C.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
< merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!