What I Have:
One array with arrays in it, like:
@my_array = (
[10, "Adam", "www.adamhomepage.com"],
[8, "Bill", "www.billhomepage.com"],
[9, "Phil", "www.philhomepage.com"],
[22, "Chris", "www.chrishomepage.com"],
);
Now I want to sort them by the first number so I get:
22, "Chris", "www.chrishomepage.com"
10, "Adam", "www.adamhomepage.com"
9, "Phil", "www.philhomepage.com"
8, "Bill", "www.billhomepage.com"
How do I do that?
@sorted = sort { *** } @notsorted;
*** can be any expression you can think of (sort of) where $a is the first value and $b is the second.
So, for example:
Numerical:
@sorted = sort { $a <=> $b } @notsorted;
Alphabetical sort:
@sorted = sort { lc($a) cmp lc($b) } @notsorted;
Alphabetical sort, reversed:
@sorted = sort { lc($b) cmp lc($a) } @notsorted;
In your case you are not just sorting an array ... you are sorting a multidimensional array based on the children.
So, the first case:
@sorted = sort { $b[0] <=> $a[0] } @notsorted;
Literally: "sort based on the first element in the child array, numerically, reversed"
The second case is similar:
@sorted = sort { $b{'points'} <=> $a{'points'} } @notsorted;