Perl-Sensitive Sunglasses | |
PerlMonks |
Re^2: Finding the max()/min()by sleepingsquirrel (Chaplain) |
on Nov 11, 2004 at 19:47 UTC ( [id://407163]=note: print w/replies, xml ) | Need Help?? |
Your recursive version of max is broken for lists like (-1,0,1,2) and (-1,undef,1,2). i.e. the code assumes it is at the end of the list whenever $next==0 or $next==undef (which isn't true in general).
Here's a snazzy (if not the most efficient) recursive version with a hat tip to Zaxo...
-- All code is 100% tested and functional unless otherwise noted.
In Section
Meditations
|
|