On 8/20/07, Ken Foskey <[EMAIL PROTECTED]> wrote:
>
> I have a piece of code that I am assured works and I cannot see why it
> would.  Code is supposed to force undefined, zero and all space to
> numeric zero to stop printf being undefined.
>
> foreach my $value (@array) {
>     if( ! $value or $value = "      " ) {
>         $value = 0;
>     }
> }
>
> Will this actually work, or as I suspect do nothing because $value is a
> copy.

$value is not a copy, it is equivalent to $array[$i] where $i is the
current offset.  Welcome to the magic of for loops.


perldoc perlsyn
       If any element of LIST is an lvalue, you can modify it by modifying VAR
       inside the loop.  Conversely, if any element of LIST is NOT an lvalue,
       any attempt to modify that element will fail.  In other words, the
       "foreach" loop index variable is an implicit alias for each item in the
       list that you're looping over.

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


Reply via email to