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).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: For vs. Foreach
by ack (Deacon) on Feb 13, 2009 at 19:16 UTC | |
Re^4: For vs. Foreach
by merlyn (Sage) on Feb 13, 2009 at 21:58 UTC | |
by BrowserUk (Pope) on Feb 14, 2009 at 04:01 UTC | |
by merlyn (Sage) on Feb 15, 2009 at 04:40 UTC | |
by BrowserUk (Pope) on Feb 15, 2009 at 05:13 UTC | |
by ikegami (Pope) on Feb 14, 2009 at 03:19 UTC | |
by Anonymous Monk on Feb 14, 2009 at 01:27 UTC |
In Section
Seekers of Perl Wisdom