perl, how to sort hash key in descending order

$hash{"v1"} = "11";
$hash{"v2"} = "22";
$hash{"v4"} = "44";
$hash{"v3"} = "33";

How do I sort the hash by the key in descending order?
rgbcofAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
reverse sort keys %hash
0
 
ozoCommented:
print "\$hash{\"$_\"} = \"$hash{$_}\"\n" for sort {$b cmp $a} keys %hash;
0
 
rgbcofAuthor Commented:
Both ways work.  Thanks Ozo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.