You're preaching to the converted. :) If you use
-MO=Deparse, you'll see that the
for(;;) gets compiled to a
while with a
continue block, the latter being where the massive performance difference weighs in. Considering that the
for(@array) form eradicates fence post errors from the root, there's rarely any good reason to use
for(;;) in Perl.
Update: I forgot. Depending on your version of
B::Deparse you may need increase the exposition level with the
-x switch in order to see what things really look like to Perl under the hood.
$ perl -MO=Deparse,-x7 -e 'for($i=0;$i<=10;$i++){}'
$i = 0;
while ($i <= 10) {
();
}
continue {
++$i
}
-e syntax OK
$ perl -MB::Deparse -e' print "$B::Deparse::VERSION\n"'
0.6
$ perl -v
This is perl, v5.6.1 built for i386-linux
[...]
Makeshifts last the longest.