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 sm
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].
>
> You should only use this form if performance matters and you know
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].
You should only use this form if performance matters and you know that
@z is smaller than 250 items (over
Ramprasad A Padmanabhan wrote:
>
> I use sort to give the max of an array something like this
>
> -
> my @z = qw(12 24 67 89 77 91 44 5 10);
> my $max = ((reverse sort{$a <=> $b} (@z))[0]);
> print "MAX = $max\n";
> ---
>
> but when I am interested only in a single max value, I need
Ramprasad A Padmanabhan wrote:
I use sort to give the max of an array something like this
-
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
---
but when I am interested only in a single max value, I need not sort the
enti
On Wed, May 28, 2008 at 9:17 AM, Ramprasad A Padmanabhan <[EMAIL PROTECTED]>
wrote:
>
> I use sort to give the max of an array something like this
>
> -
> my @z = qw(12 24 67 89 77 91 44 5 10);
> my $max = ((reverse sort{$a <=> $b} (@z))[0]);
> print "MAX = $max\n";
> ---
>
> but when
I use sort to give the max of an array something like this
-
my @z = qw(12 24 67 89 77 91 44 5 10);
my $max = ((reverse sort{$a <=> $b} (@z))[0]);
print "MAX = $max\n";
---
but when I am interested only in a single max value, I need not sort the
entire array
Is there a more effici