in reply to Re^3: Finding the max()/min()
in thread Finding the max()/min()

There's a bug in that code, try finding the max of this list...
@a = (1,0,3,2);


-- All code is 100% tested and functional unless otherwise noted.

Replies are listed 'Best First'.
Re^5: Finding the max()/min()
by elusion (Curate) on Dec 19, 2004 at 02:21 UTC
    Good catch; I forgot the edge case. Here's the fix:
    sub max { my $max = shift; return $max if not @_; my $next = shift; unshift @_, $max > $next ? $max : $next; goto &max; }