4.10. Reversing an ArrayProblemYou want to reverse an array. Solution
Use the # reverse @ARRAY into @REVERSED @REVERSED = reverse @ARRAY;
Or use a for ($i = $#ARRAY; $i >= 0; $i--) { # do something with $ARRAY[$i] } Discussion
The
If you're using # two-step: sort then reverse @ascending = sort { $a cmp $b } @users; @descending = reverse @ascending; # one-step: sort with reverse comparison @descending = sort { $b cmp $a } @users; See Also
The Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|