?
Solved

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

Posted on 2006-10-23
3
Medium Priority
?
464 Views
Last Modified: 2008-02-07
Hi. I need to sort a perl array in descending then printing out the top 5? help would be greatly apreciated.
0
Comment
Question by:micromarch
3 Comments
 
LVL 4

Accepted Solution

by:
NorCal2612 earned 1000 total points
ID: 17793097
@array = sort { $b <=> $a } @array;

for ($i = 0; $i < 5; $i++) { print $array[$i] . "\n"; }
0
 
LVL 85

Expert Comment

by:ozo
ID: 17793683
@array = reverse sort @array;
print "@array[0..4]\n";
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
Progress
Introduction to Processes

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question