After I sent this I had a flash of enlightenment:
$max = (sort {$a <=> $b} @_)[-1];
May be slower, though, I don't know.
- B
On Apr 11, Bryan R Harris said:
>$someVar = max(@listofvalues);
>
>Is there a function in perl like this?
You could use the List::Util module (from CPAN). Or, you could write your
own:
sub max {
my $max = shift;
for (@_) { $max = $_ if $_ > $max }
return $max;
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]