develooper Front page | perl.perl5.porters | Postings from November 2011

Re: Explanation of "for" and "foreach" in perldoc

Thread Previous | Thread Next
From:
Abigail
Date:
November 28, 2011 23:30
Subject:
Re: Explanation of "for" and "foreach" in perldoc
Message ID:
20111129073001.GB5387@almanda
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.



Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About