Solved

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

Posted on 2006-10-23
3
429 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 113
how to send memory stream from ics Client To ics server ? 11 110
Scripting vs. Programming languages 25 165
What does != "" mean in programming 8 32
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

777 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