Solved

perl, how to sort hash key in descending order

Posted on 2011-03-18
3
716 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 173
HTTP Error 502.2 - Bad Gateway 3 216
Put query string from URL request -  PERL HTTP Daemon 2 78
Perl string filter 5 79
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

772 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