http://www.perlmonks.org?node_id=594187


in reply to Re: Mutable foreach list?
in thread Mutable foreach list?

Right - I'm on forbidden ground. Perlsyn says:
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
I guess what's happening is something like this (psudocode):
$it = &make_list_into_iterator(LIST); $count = $it->figure_out_element_count; while ($count-- > 0) { $_ = $it->next; CODE }
Which fits the behaviour I see.

-- zigdon