@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..
Perl hashes do not have order. You must either switch them to arrays, or sort them upon usage (e.g. when you need to iterate over that hash).
The first solution could look like:
…
Second solution would be: