?
Solved

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

Posted on 2006-10-23
3
Medium Priority
?
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 84

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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.
Progress
Introduction to Processes
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

765 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