I have a hash %d,i want the top five valued keys.I did the following wich worked but is there anything more effecient? @p=(reverse sort{$d{$a}<=>$d{$b}} keys%d)[0..4];
ssdeep
9
Light Poster
d5e5
commented:
Good question. I think the answer is 'no' but I can't prove it.
+9
Recommended Answers
Jump to PostWe can take the greatest five from a hash without sorting. I don't know if that makes it more efficient. For example, the following prints the five colors having the longest wavelengths.
#!/usr/bin/perl use strict; use warnings; my %d = (violet => 400, red => 650, indigo …
All 4 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.