On Wed, 30 May 2001, E. Alan Hogue wrote:
...
> foreach $field (@fld_vals) {
>       while ($field = '') {
>               push (@nulls,$id);
>       }
> }
> 
> My idea was that $id would be, for instance, the
> primary key value so that I could go look at the
> record later. 
> 
> Well, it didn't do what I wanted, but what really
> confuses me is what it actually did. When I went
> through the program in the debugger, it looked like my
> while statement was actually _assigning_ '' to each
> element of @fld_vals, thereby erasing the data in that
> array.
> 
> Can anyone tell me why it did this?

It does that because = is the assignment operator.

If you want to compare strings you want to use the eq operator, eg:

 foreach $field (@fld_vals) {
        if ($field eq '') {
                # I assume these are defined somewhere else
                push (@nulls,$id);
        }
 }

For a complete description of perls operators, see perldoc perlop.

-- 
Tony

Reply via email to