On Aug 21, [EMAIL PROTECTED] said:
>I change the value of $aString but ... it turns out that I am **also**
>altering the values of the Strings held in the Array.
A for-loop aliases a variable to each element of the list you're looping
over. That's why you can't say:
for (1, 2, 3, 4) {
$_++;
}
You can't change the value of 1. This is documented in perlsyn, under the
"Foreach Loops" heading:
If any element of LIST
is an lvalue, you can modify it by modifying VAR inside the
loop. That's because the foreach loop index variable is an
implicit alias for each item in the list that you're looping
over.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Re: foreach() loop creates $aString-s that I modify , AND they modifythe Array Contents !?
Jeff 'japhy/Marillion' Pinyan Wed, 22 Aug 2001 13:50:58 -0700
- foreach() loop creates $aString-s that I mod... Greg_Presedo-Floyd
- Jeff 'japhy/Marillion' Pinyan
