http://www.perlmonks.org?node_id=406898


in reply to Finding the max()/min()

A recursive solution for a list of numbers: (the idea to get max for a list is originally gotten from elusion's post)

use strict; use warnings; print max(1.23,2.6,55.1,1.11,4,5); print min(1.23,2.6,55.1,1.11,4,5); sub max { splice(@_, ($_[0] > $_[1]) ? 1 : 0, 1); return ($#_ == 0) ? $_[0] : max(@_); } sub min { splice(@_, ($_[0] > $_[1]) ? 0 : 1, 1); return ($#_ == 0) ? $_[0] : min(@_); }