- or download this
If any part of LIST is an array, "foreach" will get very confus
+ed if
you add or remove elements within the loop body, for example wi
+th
"splice". So don’t do that.
- or download this
@foo = map { 'd' eq $_ ? ($_,'h') : $_ } @foo;
# puts 'h' right after 'd'
- or download this
my @extras;
foreach my $x (@foo) {
...
# didn't print 'h'. But if we add:
print foreach @extras;
# that works ... but duplicates code.
- or download this
{
my @extras;
...
{
print $x;
}