how to sort a perl array in descending and printing out the top 5?

Hi. I need to sort a perl array in descending then printing out the top 5? help would be greatly apreciated.
LVL 2
micromarchAsked:
Who is Participating?
 
NorCal2612Commented:
@array = sort { $b <=> $a } @array;

for ($i = 0; $i < 5; $i++) { print $array[$i] . "\n"; }
0
 
ozoCommented:
@array = reverse sort @array;
print "@array[0..4]\n";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.