Solved

perl, how to sort hash key in descending order

Posted on 2011-03-18
3
701 Views
Last Modified: 2012-08-13
$hash{"v1"} = "11";
$hash{"v2"} = "22";
$hash{"v4"} = "44";
$hash{"v3"} = "33";

How do I sort the hash by the key in descending order?
0
Comment
Question by:rgbcof
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 35169892
reverse sort keys %hash
0
 
LVL 84

Expert Comment

by:ozo
ID: 35169895
print "\$hash{\"$_\"} = \"$hash{$_}\"\n" for sort {$b cmp $a} keys %hash;
0
 

Author Closing Comment

by:rgbcof
ID: 35170081
Both ways work.  Thanks Ozo.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now