>>>>> "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:

Dan> On Wed, 2004-01-07 at 20:39, Paul Harwood wrote:
>> I am reading through a book on Objects and References and I don't
>> understand this statement:
>> 
>> $sum +=  $_ for split //;

Dan> FWIW, for is synonymous with foreach.

Syntactically, "for" can always be swappped with "foreach".
However, there are definitely two different styles of loops.

Traditionally, the "for" loop is the "C-style for loop", with an
initializer, test, and iterator expression trio.  And "foreach" loop
is the "csh-style foreach loop", with a single scalar being walked
through a list of values.

But in Perl, you can spell either of these loops "for" or "foreach".
Most Perl hackers tend to optimize for the shorter word when possible,
although in Learning Perl, we were careful to always use the "proper"
word.

print "Just another Perl (book) hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to