ARGH, no, don't do that! Actually by now you've probably already seen my earlier reply. Argel was exactly right and the suggested fix of using an explicit variable in place of the default variable is a much better solution than resorting to a C style for loop.
As an aside for and foreach are aliases in Perl. It is the syntax that distinguishes between the Perlish iterating over a list behaviour and the Cish for loop behaviour. Personally I use for in both cases because I'm lazy and can't be bothered typing the superfluous "each".
The important lesson to learn from this is that the special variables are effectively globals and may change without notice, especially during the processing of a called subroutine. The default variable is most prone to this issue and should be avoided where possible in any non-trivial script.
In reply to Re^3: Why are elements of my array getting deleted?
by GrandFather
in thread Why are elements of my array getting deleted?
by iKnowNothing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |