This is a documented feature of foreach. You can read all about it at the perlsyn page, under the Foreach Loops heading. This basically sums it up:
That's because the foreach loop index variable is an implicit alias for each item in the list that you're looping over.
So modifying it will change the element in the list, see?
--In reply to Re: Strange array reference behaviour (bug?)
by edan
in thread Strange array reference behaviour (bug?)
by agrundma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |