max#

Return the numerically largest value in the list.

Synopsis#

my $hi = max @values;
my $hi = max 3, 9, 12;           # 12

What you get back#

A single number. If every argument is an integer the result is returned as an integer; otherwise it is returned as a float. An empty list yields undef.

Examples#

my $n = max 1..10;               # 10
my $n = max @bar, @baz;          # largest across concatenated lists
my $n = max();                   # undef

Edge cases#

  • Empty list returns undef.

  • Strings are compared numerically (use maxstr for lexical order).

Differences from upstream#

Fully compatible with upstream.

See also#

  • min — the numerical minimum counterpart.

  • maxstr — string-wise maximum (gt semantics).

  • reduce — custom maxima (e.g. by a key function).