Re: For loop aliasing AND changing an array within a loop.

2003-01-24 Thread Rob Dixon
Hi Michael. Michael Hooten wrote: > While stepping through the code I wrote, I distinctly noted that the > substitution on $_ did NOT affect the array and vice versa. If you watch carefully what Perl is doing, it aliases correctly _until_ you choose to modify the array. After this the correct val

RE: For loop aliasing AND changing an array within a loop.

2003-01-24 Thread Michael Hooten
PROTECTED] Subject: Re: For loop aliasing AND changing an array within a loop. On Wed, Jan 22, 2003 at 02:10:34PM -0800, John W. Krahn wrote: > Zeus Odin wrote: > > I think I read somewhere that you should NOT delete array elements from > > within a loop. However, the following

Re: For loop aliasing AND changing an array within a loop.

2003-01-22 Thread John W. Krahn
Paul Johnson wrote: > > On Wed, Jan 22, 2003 at 02:10:34PM -0800, John W. Krahn wrote: > > > > I think that you are thinking of hashes. > > From perlsyn: > > If any part of LIST is an array, "foreach" will get very > confused if you add or remove elements within the loop > body, for example

Re: For loop aliasing AND changing an array within a loop.

2003-01-22 Thread Paul Johnson
On Wed, Jan 22, 2003 at 02:10:34PM -0800, John W. Krahn wrote: > Zeus Odin wrote: > > I think I read somewhere that you should NOT delete array elements from > > within a loop. However, the following works very well. > > I think that you are thinking of hashes. From perlsyn: If any part of LIS

Re: For loop aliasing AND changing an array within a loop.

2003-01-22 Thread John W. Krahn
Zeus Odin wrote: > > When you loop through an array > >for(@array){ ... } > > should not each array element be aliased into $_: if you change $_, you > also change the element? Yes, that is correct. > This is what I remembered. However, a problem I > just encountered shook this recollectio