Re: efficient max() function from sort

[email protected] ("John W. Krahn")
Newsgroups perl.beginners
Message-ID <[email protected]>
Chas. Owens wrote:
> On Wed, May 28, 2008 at 5:07 PM, Rob Dixon <[email protected]> wrote:
> snip
>>  $max = (sort {$a <=> $b} @z)[-1];
> snip
> 
> my $max = (sort { $b <=> $a } @z)[0];
> 
> is slightly faster than using [-1].

Or:

my ( $max ) = sort { $b <=> $a } @z;



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.