in reply to Re: Re: finding highest number
in thread finding highest number
(untested)   (and, as said, of course the sort method would be better, at least for small arrays, and would be even more better for finding the top three values:  (sort ..., @array)[-3..-1] )use strict; my @array = (1, 5, 4, 10, 20, 2, 1, 3, 7); my @hi = (0) x 3; # '0' assumes positive #'s foreach (@array) { $_ <= $hi[0] and next; @hi = (sort $a<=>$b, @hi, $_)[-3..-1]; } print "@hi";
|
---|