I can say that it's not a good idea. Look at what you get when you do this:
my @foo = qw/a b c d e f g/;
for my $x (@foo) {
push @foo, 'd' if $x eq 'd';
print $x;
}
The iterator keeps marching through the d's, adding new ones to the end. A better way to do it might be:
push @foo, map {$_ eq 'd' ? 'd' : ()} @foo;
print for @foo;
I doubt that it's implmentation-dependent. The iterator is stepping through the array, and by the time it gets to the end of the array, there's another element there to step through.
Still, it's not a nice trick to play. Here's an even more diabolical one:
for (@foo) {
print;
shift(@foo) if $_ eq 'c';
}
print "\n@foo\n";
Caution: Contents may have been coded under pressure.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.