[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] "," instead of ";" in "for"



> Any thoughts, wrong conclusions?

Shamelessly lifted from MPPE.  However, just consider this an impromptu 
book review, and the following as fair use under copyright law.  Go out 
and avail yourself a copy of "MacPerl Power and Ease," by Vicki Brown and 
Cris Nandor!

  for

    for (EXPR; CONDITION; EXPR2) {...}

    Repetition control flow modifier.  Upon startup of a for loop,
    the initial state is set by EXPR and the truth of CONDITION is
    checked.  If the condition is true, the block is executed.  On
    the next and all subsequent interations, EXPR2 is evaluated 
    and CONDITION is checked again.  If CONDITION is still true,
    the block is executed again.  The loo will continue,
    evaluating EXPR2 each time for as long as CONDITION remains
    true.  See also: foreach

  foreach

    foreach SCALAR (LIST) {...}

    Repetition control flow modifier.  A foreach loop is used to
    evaluate a block of code for each of a known list of scalars,
    typically the elements of an array or hash.  Note that the
    loop variable, SCALAR, becomes a reference to the actual list
    element under consideration; modifying this variable will
    modify the original array or hash!  See also: for.

    NOTE: for and foreach are actually synomyms for the same
    command, and can be used interchangeably with the same syntax
    Conventionally, the are most often used as we have shown.

Okay, so when you use the comma syntax, what you really MEAN is 
"foreach".  When you use the semi-colon syntax you mean "for".  So not 
suprisingly, the behavior changes.  The "foreach" expects a SCALAR as 
it's argument. Called in a void context, it uses $_.

So, for the sake of clarity, when using the comma syntax,  call it 
"foreach" and when using the semi-colon syntax "for".  This will make it 
clear to you and everyone else what's happening.

--B

# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org