Problems? Is your data what you think it is? | |
PerlMonks |
Re^3: resetting a foreach loop!by brostad (Monk) |
on Nov 17, 2017 at 11:27 UTC ( [id://1203655]=note: print w/replies, xml ) | Need Help?? |
Sorting the same array twice and assigning the results to two new arrays, potentially very long, is a bit wasteful when all you want is to find the smallest and largest value in the array. You could for instance do something like this:
my($largest, $smallest) = (sort { $b <=> $a } @array)[0,-1];
In Section
Seekers of Perl Wisdom
|
|