Rob Dixon wrote:

> R. Joseph Newton wrote:
> >
> > Rob Dixon wrote:
>
> > ...has the same effect as printing from inside the loop.
> > Which means that my array contents
> >
> > have either been effectively modified, or totally hashed,
> > depending on whether that was the desired effect.
>
> ..except that, to be picky, you need
>
>   print ucfirst "$_\n" for @lines

Yep

> outside the loop. And that this is a warning for 'foreach'
> in general, not specifically for $_. If your loop had been
>
>   foreach my $line (@lines) {
>     :
>   }
>
> then the named scalar would similarly have been aliased
> with the array elements.
>
> Cheers,
>
> Rob

Ouch!  Thanks for the heads-up!  That is downright scary.  Strangely
enough, I don't think I have ever been bitten by that in actual coding.
Maybe this is a good argument for the approach I alluded to earlier in
the thread, of assigning the value of the it variable to a named scalar
first thing inside the loop.  Geez, now I'll have to scan through my old
code and see how I have been hamdling this and keeping data intact.

Joseph


-- 
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