Is there an existing Perl max() function that finds the largest number in a list?

A

Avner

Hi,

I want to find the largest number in a list.
Is there an existing Perl max() function that will let me do that?
I couldn't find any such function in the Perl documentation.

I know it is easy to implement but, this is just an example for other
functionalities that I need. I don't want to reinvent the wheel every
time.

Thanks,
Avner
 
G

Gunnar Hjalmarsson

Avner said:
I want to find the largest number in a list.
Is there an existing Perl max() function that will let me do that?
I couldn't find any such function in the Perl documentation.

See the CPAN module List::Util.
I know it is easy to implement but, this is just an example for other
functionalities that I need.

Not sure why you say that. For other functionalities you'll probably
need other built-in functions or modules... Or "reinvent wheels".

sub max {
my $max = $_[0];
for ( @_[ 1..$#_ ] ) {
$max = $_ if $_ > $max;
}
$max
}
 
A

A. Sinan Unur


Apparently not. However, it lives under C:\opt\Perl\lib on my installation
rather than C:\opt\Perl\site\lib, so I assumed it was a standard module.

Thanks for the correction.

Sinan
 
D

DJ Stunks

A. Sinan Unur said:
Apparently not. However, it lives under C:\opt\Perl\lib on my installation
rather than C:\opt\Perl\site\lib, so I assumed it was a standard module.

List::Util and Scalar::Util have been part of the Perl standard library
since 5.8.

-jp
 
D

DJ Stunks

S

Sisyphus

Gunnar Hjalmarsson said:
Confusing as always... If that's the case, why aren't they listed at
http://search.cpan.org/~nwclark/perl-5.8.8/ ?

Looks to me that the only way to get the modules mentioned there is to
downoad the perl source - there's no place on CPAN where you can download
them individually. They are therefore, perhaps, all Nick's responsibility -
which could explain their listing under his ownership. (I'm sure Nick knows
how to delegate, btw.)

Conversely, I think that any core modules not mentioned there *can* be
downloaded individually from CPAN. They are the responsibility of someone
other than Nick - which would be the reason they are not listed under his
ownership.

Or something like that ..... :)

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top