It doesn't? Since when is (0 .. $#array) free to return the numbers in a non-consecutive order? Perlop describes it as:
In list context, it returns a list of values counting (up by ones) from the left value to the right value.
How's that different from
for (my $i = 0; $i < @array; $i++)
which also says to count by one, from the left value up to the right value? | [reply] [d/l] [select] |
Sure, they have the same semantics if you write the C-style for loop to do what Perl does for you automatically with the range loop. Everyone agrees about that.
The difference is that with the C-style for loop, you the programmer are the one controlling the iteration by explicitly providing the loop termination condition as well as the loop increment. That is the structural code. If you need that control in specific cases, that's fine. That's why both styles of loop exist. You're a grown up and you get to decide what's easiest to read, simplest to maintain, quickest to write, or whatever other criteria you like. Most every Perl user agrees about that too.
... but when you're explicitly doing things that Perl will happily do for you and writing more code (measured by statements or ops in the optree), you can probably get rid of synthetic code.
| [reply] |