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

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

Thread Previous
From:
Tom Christiansen
Date:
November 29, 2011 09:25
Subject:
Re: Explanation of "for" and "foreach" in perldoc
Message ID:
27205.1322587513@chthon
>I don't see it as a special case. As far as I'm concerned, it's not a
>foreach loop at all rather than a special case of foreach loops.

>   - It performs a different function than foreach loops.
>   - It's implemented differently than C-style loops and foreach loops.
>   - It performs differently than foreach loops.

>You lump it in as a foreach loop, so either you are unaware of the above,
>or you *do* see it as a special case of foreach loops.

>People are quite aware of the difference. They avoid it like the plague (in
>favour of C-style loops) until they learn it's not a foreach loop. But when
>it comes time to discussing "for" vs "foreach", it's automatically just a
>special case of foreach loops. I just find that weird.

Eric, you're coming at from the point of view of thinking about internal 
op codes and how it gets implemented.  You're not thinking of it from 
the end-user point of view, for whom the semantics is what counts.
That it gets optimized into something very different internally does
not change its semantics, and therefore is not a special case to the user.

--tom

Thread Previous


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