in reply to Unexpected behavior of '..' lists

I think that it means that foreach (#blah alah blah) created an anonymous array, that can be reused :) I don't know if it is a bug or a feature of Perl :)

The anonymous array is not created only in the case of for(number..number), as ikegami mentioned, as such loops are replaced by counting ones.

The shortest illustrating example:

for (0..2) { foreach my $x (0..1, ()) { print +($x .= " wassap? ") . "\n"; } }

It prints:
0 wassap? 1 wassap? 0 wassap? wassap? 1 wassap? wassap? 0 wassap? wassap? wassap? 1 wassap? wassap? wassap?
UPDATE:

B::Deparse displays that it ocuurs only to arrays generated by the .. operator.

UPDATE 2:

I just realised that i used the feature of modifyable '..' arrays in my code :)

print map { s/$/\n/;$_ } (0..1);
works, while
print map { s/$/\n/;$_ } (0,1);
produces a fatal error :) So we can create one more example:
for (0..1) { print map { s/$/!\n/;$_ } (0..1); }

The bug is that anonymous arrays created by .. are globally scoped :) and I don't think it'a an optimisation for Perl.

Finally, i think that the title of the node is incorrect :)). The good title would be Unexpected behavior of '..' lists. Or smth like this :)


     s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print