http://www.perlmonks.org?node_id=743663


in reply to Re^2: For vs. Foreach
in thread For vs. Foreach

Good question.

It is truly optimised to count from the first to the last without creating a list. You could lump it as an optimisation since the effect is the same as if ".." was the range operator. (It's not.) I choose not to.

People already have a concept of a counting loop from countless other languages. They expect to find a counting loop and presume Perl provides the C-style for loop that purpose. I'm giving them what they are looking for.

By labeling it as a counting loop, I try to clear the false perception that it should be avoided for efficiency reasons, in order to encourage the use of the for my $i ($x..$y) over the less readable for (my $i=$x; $i<=$y; ++$i).