Min and max functions in Perl

Posted: 1st February 2012 by Tim in Perl
Tags: , , , , ,

Min and max functions are available in perl, but you need to load them first. To do this, add

use List::Util qw[min max];

to the top of the script. These functions take a list of numbers and return the min/max of that list. The list can have 1 number or 100 – it doesn’t matter:

use List::Util qw[min max];

print min(1,3) . "\n";
print max(1,2,3,4,5) . "\n";
print min(1) . "\n";

Will print:

1
5
1

  1. mpz says:

    Useful thx dude !

    ps: nice theme

  2. Lorenzo says:

    Thank you from Florence!

  3. Istvàn Pais-Budapest says:

    Thank you !