@aoaoh;
$aoaoh[0][0]{21} = 31;
$aoaoh[0][0]{22} = 31;
$aoaoh[0][0]{23} = 17;
for $k (0 .. $#aoaoh) {
for $i(0.. $#aoaoh) {
for $val (keys %{$aoaoh[$i][$k]}) {
print "$val=$aoaoh[$i][$k]{$val}\n";
}
}
}
The output is:
22=31 21=31 23=17
but i expect it to be
21=31 22=31 23=17
Please tell me where is this wrong.
Also how do I sort the values so that i get the output as
23=17 22=31 21=31 (if 2 keys have same value then key with higher value come first)
Sounds like you want:
for $val (sort keys %{$aoaoh[$i][$k]}) {
and:
for $val (reverse sort keys %{$aoaoh[$i][$k]}) {
Although from your comment it looks like you don't want a pure reverse sort. You want to create your own sort function:
for $val (sort {$aoaoh[$i][$k]->{$a} <=> $aoaoh[$i][$k]->{$b} || $a <=> $b} keys %{$aoaoh[$i][$k]}) {