sorting hashes inside an array on values
Posted
by srk
on Stack Overflow
See other posts from Stack Overflow
or by srk
Published on 2010-03-25T09:20:30Z
Indexed on
2010/03/25
9:23 UTC
Read the original article
Hit count: 385
@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..
© Stack Overflow or respective owner