My expectation was your number 2. Loop over the modified array. And that's what it does in my experiments. It looks like Perl is being efficient and rather than constructing a new list to loop over that is just a verbatim copy of the array it already has access to, it's using that array as it's loop list and the implementation of arrays in Perl is such that adding elements on the end of the array doesn't mess up the iterator used by the for loop. At least for the small size arrays I've been working with. Thinking about it further I can imagine Perl doing this until the array gets to a large enough size that it can't be held in the current location in memory so it moves it around in a way that could invalidate or reset the iterator.
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||