How can I maintain a sorted hash in Perl?
- by srk
@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,
},
);
I want the hashes in each array index sorted in reverse order based on values..
@sorted = sort { ........... please fill this..........} @aoh;
expected output
@aoh =(
{
4 => 8,
5 => 9,
3 => 15,
},
{
5 => 6,
3 => 11,
4 => 25,
},
{
5 => 5,
3 => 5,
4 => 18,
},
{
2 => 7,
1 => 11,
0 => 16,
},
{
1 => 13,
0 => 21,
2 => 31,
},
{
0 => 11,
1 => 14,
2 => 31,
},
);
Please help.. Thanks in advance..
Stating my request again: I only want the hashes in each array index to be sorted by values.. i dont want the array to be sorted..