in reply to Re^3: grep, map vs. foreach performance
in thread grep, map vs. foreach performance

No, while isn't for. It is optimized to a for(;;) in the case where it is used as while(SOME_TRUE_CONSTANT). It is also optimized away in the case where it is used as while(SOME_FALSE_CONSTANT).

$ perl -MO=Deparse -e 'while (0) {}' ; -e syntax OK $ perl -MO=Deparse -e 'while (1) {}' for (;;) { (); } -e syntax OK $ perl -MO=Deparse -e 'while (@_) {}' while (@_) { (); } -e syntax OK

For that matter, even though for and foreach are synonymous, what's in the parens determines how perl actually parses them:

$ perl -MO=Deparse -e 'for (;;) {}' for (;;) { (); } -e syntax OK $ perl -MO=Deparse -e 'foreach (;;) {}' for (;;) { (); } -e syntax OK $ perl -MO=Deparse -e 'for (@_) {}' foreach $_ (@_) { (); } -e syntax OK $ perl -MO=Deparse -e 'foreach (@_) {}' foreach $_ (@_) { (); } -e syntax OK
-sauoq
"My two cents aren't worth a dime.";