in reply to not able to get last index of array
my @numbers = (15,5,7,3,9,1,20,13,9,8, 15,16,2,6,12,90); printf ('The maximum number is %s%s', max(@numbers), "\n"); sub max { my $first = shift; while ($#_ >= 0) { # until list exhausted if ($first >= $_[0]) { # keep throwing away inferiors shift; } else { $first = shift; # crown the new king } } return $first; # end of list, inferiors exhausted }
One world, one people
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: not able to get last index of array
by hippo (Archbishop) on Jun 02, 2016 at 12:46 UTC |