In perl, I have a hash that looks like the following:
$hash{key1}->{a} = 1;
$hash{key1}->{b} = 3;
$hash{key2}->{a} = 4;
$hash{key2}->{b} = 7;
$hash{key3}->{a} = 2;
$hash{key3}->{b} = 5;
How can I sort the keys of this hash by the value of key a
. For instance, sorting the above hash in numerical ascending order by the values of key a
would give: key1,key3,key2.
perldoc perlreftut
you don't need any of the->
in your example. This makes for cleaner looking multilevel hashes. – Joel Berger