in reply to Re: changing array size in foreach loop: is it safe?
in thread changing array size in foreach loop: is it safe?
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 with "splice". So don’t do that.Isn't this just saying if one is manipulating an element that is itself an array, not the LIST itself? I would think as long as one stuck to scalars, it should be OK, although one would have to be careful.
@foo = qw/a b c d e f g/; map{ push @foo, 'h' if /^d$/ } @foo; print @foo, "\n";
|
|---|