Well, technically, doesn't 0..$#array create an (anonymous) array, which reverse then reverses? :)
Technically no. The 0..$#array just creates a list from
zero to the last index, reverse 0..$#array is the list
of indices reversed. So we are not reversing the array, just creating
a slice with with reversed indices and assigning that slice to the a
slice with all the indices in order. I imagine a built-in array
reversal would be more like Ruby's array.reverse!
method.
| [reply] [Watch: Dir/Any] [d/l] [select] |
So we are not reversing the array...
...just reversing the list. List, array; array, list. While they are technically different (one is a Perl data structure, while the other is an anonymous collection of scalar values), I don't see how that difference really matters in this case. =) You're still using Perl's built-in to reverse a list/array, whether it's the original array, or the list of array indices. It's just semantics.
I mean, by those standards, reverse technically accepts a LIST, not an ARRAY (and will flatten multiple arrays into a single list, for example), so you should be able to do: @array = reverse @array;, since reverse isn't actually reversing the array but, rather, the list passed to it (after which, the reversed list is passed back and stored into the original array, replacing the original contents). Of course, as Aristotle points out, both of these methods (using Perl's built-in reverse, and your method of reversing the list of indices) fail the "in-place" clause of the original problem, so it's all moot. =)
bbfu
Black flowers blossum
Fearless on my breath
Teardrops on the fire
Fearless on my breath
| [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] [d/l] |