in reply to Re^3: Strange loop output
in thread Strange loop output
Consider a very simple loop like this:
my @a; for (qw/a b c/) { push @a, $_; print (join ', ', @a), "\n"; }
In the first iteration, @a contains a, so the output is
a
In the second iteration, @a contains a, b, so the total output is
a # output from previous iteration a, b # output from current iteration
In the third iteration it will print a, b, c, so you'll see a total of three a in the output - probably the duplicates you complained about.
If you move the print out of the loop, you just get a, b, c because that's what @a contains.
|
|---|