Solved

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

Posted on 2006-10-23
3
430 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 250 total points
ID: 17793097
@array = sort { $b <=> $a } @array;

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

Expert Comment

by:0xC0DEB07
ID: 17793265
0
 
LVL 84

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 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