Re: [perl #75720] for(@a) optimisation causes problems

[email protected] (Dave Mitchell)
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
On Sun, Jun 13, 2010 at 06:23:30PM -0700, Father Chrysostomos wrote:
> $ perl -le' @a = (1,2,3); print shift @a for @a'
> 1
> 2
> 
> $ perl -le' @a = (1,2,3); print shift @a for (),@a'
> 1
> 2
> 3
> 
> There seems to be some optimisation for ‘for @array’ that has strange  
> side-effects.

The first one iterates over the elements of an array, the second over the
elements of a list. The array is being modified mid-iteration, while the
list isn't, which is why you see different results.

-- 
Atheism is a religion like not collecting stamps is a hobby
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.