in reply to Re: Finding target unspecified value
in thread Finding target unspecified value
boftx:
Latnam doesn't generate any negative numbers in his or her @source array, but if all the numbers were negative, the results would be spurious. List::Util::max and min don't have this problem (although they don't produce any index information; maybe see List::MoreUtils::first_index for this).
>perl -wMstrict -le "my @source = ( -1, -2, -33, -4 ); ;; my $maxseen = 0; my $seen_at = 0; my $cntr = 0; for ( @source ) { if ( $_ > $maxseen ) { $maxseen = $_; $seen_at = $cntr; } ++$cntr; } ;; print qq{max $maxseen at index $seen_at}; " max 0 at index 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Finding target unspecified value
by boftx (Deacon) on Oct 21, 2013 at 03:42 UTC |