Each element in the array is a reference to an anon hash. Loop over these references, then deference to get the keys to put into sort. output of sort is sorted keys. see below.
use strict;
use warnings;
my @aoh =(
{
3 => 15,
4 => 8,
5 => 9,
},
{
3 => 11,
4 => 25,
5 => 6,
},
{
3 => 5,
4 => 18,
5 => 5,
},
{
0 => 16,
1 => 11,
2 => 7,
},
{
0 => 21,
1 => 13,
2 => 31,
},
{
0 => 11,
1 => 14,
2 => 31,
},
);
foreach my $href (@aoh)
{
my @sorted_keys = sort {$href->{$a} <=> $href->{$b} } keys %$href;
foreach my $key (@sorted_keys)
{
print "$key => $href->{$key}\n"
}
print "\n";
}
__END__
4 => 8
5 => 9
3 => 15
5 => 6
3 => 11
4 => 25
3 => 5
5 => 5
4 => 18
2 => 7
1 => 11
0 => 16
1 => 13
0 => 21
2 => 31
0 => 11
1 => 14
2 => 31
|