kansas-city-pm-list  

Re: 5.8.0 changes file

Andrew Moore
Thu, 10 Oct 2002 12:48:15 -0700

On Thu, Oct 10, 2002 at 02:42:59PM -0500, david nicol wrote:
> 
> I don't want to bother perl5-porters with my questions...
> 
> > =head2 Modifying $_ Inside for(..)
> > 
> >    for (1..5) { $_++ }
> > 
> > works without complaint.  It shouldn't.  (You should be able to
> > modify only lvalue elements inside the loops.)  You can see the
> > correct behaviour by replacing the 1..5 with 1, 2, 3, 4, 5.
> 
> Is there a bug?  There a lots of places where you want to modify $_
> within loops.  Consider:
> 
>               for (@names){
>                       s/\b([a-z])/toupper($1)/g;
>                       print;
>               }
> for one example.
> 
> 
> Who says that modifying $_ here causes a problem?  It doesn't
> break the looping.  Do they want it break the looping, as in
> a for(;;) construction?

I believe the point is that @names is an lvalue. If you want
to loop over the integers 1 through 5 _and_change_them_, use an lvalue.

my @fiver = (1..5);
foreach ( @fiver ) {
   $_++;
}

or somesuch. Know what I mean?

-Andy