in reply to Unexpected behavior of '..' lists
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:
It prints:for (0..2) { foreach my $x (0..1, ()) { print +($x .= " wassap? ") . "\n"; } }
UPDATE:0 wassap? 1 wassap? 0 wassap? wassap? 1 wassap? wassap? 0 wassap? wassap? wassap? 1 wassap? wassap? wassap?
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 :)
works, whileprint map { s/$/\n/;$_ } (0..1);
produces a fatal error :) So we can create one more example:print map { s/$/\n/;$_ } (0,1);
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 :)
|
|---|