Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: sort hash by length of the values

Perl:  sort hash by length of the values
{filelink=14716}

#!/usr/bin/perl -w
my %myCities = ("January" => 31,
           "February" => 28,
               "Mars" => 31,
               "April" => 30,
               "May" => undef);
 # sorting
foreach $elem (sort {  length($myCities{$a})  length($myCities{$b}) }
                keys %myCities)
{
    print "$myCities{$elem} ==> $elem.
";
}

Users who found this page were searching for:

  • Perl Sort Hash by Value
  • sort value pair by length

No comments yet.

Leave a Comment