On Sat, Nov 26, 2011 at 04:44:34PM -0700, Tom Christiansen wrote: > >The Perl documentation sometimes refers to "for" as C-style only and > >"foreach" as the Perl-style only construct. When actually they're > >synonyms for the same thing. > > >I've pushed the two following patches to avar/foreach-docs that fix a > >small amount of this discrepancy, but I wonder why it the > >documentation was written like this. Were the two subtly different at > >some point in the past, or is it just that the authors of the > >documentation wanted people to write "for" for the C-style ones and > >"foreach" for the Perl-style ones, even though they're synonyms? > > It was a Huffman error. The more commonly used one should have the > shorter name. In the Bourne shell, for means what foreach means in > the csh. Since the distinction is made based on semicolons, not on > the name, there is never any reason to spell it foreach, and several > reasons not to. > I use "for (my $i; $i < @array; $i ++)" and "foreach my $key (@array)", because when *reading it out loud*, it sounds better than the other way around, or when having a single name for it. I really don't care about 4 more keystrokes. AbigailThread Previous | Thread Next