On Thu, 8 Nov 2001, Dan Sugalski wrote: > Gack. Looks like a mis-placed optimization in perl 5. The list of a foreach > is *supposed* to flatten at loop start and be static. Apparently not. :) > > Care to file the perl 5 bug report, or shall I?
It's not a bug. Check out the "Foreach Loops" section in perlsyn, where you'll find: If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop. Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail. In other words, the "foreach" loop index variable is an implicit alias for each item in the list that you're looping over. -sam