K
kj
The following short module illustrates a puzzling bug:
use strict;
package Foo;
my $x = +{ 1 => 'one' };
sub foo {
keys %$x if 0; # should do nothing
my $y = eval '$x'; die if $@;
printf "%d\n", scalar keys %$y;
}
1;
__END__
OK, now: the following one-liner produces the expected output:
% perl -MFoo -e 'Foo::foo()'
1
....but if one comments-out the first line of Foo::foo, the output changes:
% perl -MFoo -e 'Foo::foo()'
0
Note that the line that was commented out should do nothing, because
it ends with the conditional qualifier "if 0". Therefore, this
line is essentially a no-op and should have absolutely no effect
on the execution of this code.
I'm seeing this behavior with v. 5.8.8. Does anyone see it also
with more recent versions?
I have no doubt that this is a bug, but I can't begin to figure
out why it's happening. Any light that may be thrown on this puzzle
would be much appreciated.
Also, is there a better solution to this problem than including
silly "voodoo code" like the first line in Foo::foo?
TIA!
Kynn
use strict;
package Foo;
my $x = +{ 1 => 'one' };
sub foo {
keys %$x if 0; # should do nothing
my $y = eval '$x'; die if $@;
printf "%d\n", scalar keys %$y;
}
1;
__END__
OK, now: the following one-liner produces the expected output:
% perl -MFoo -e 'Foo::foo()'
1
....but if one comments-out the first line of Foo::foo, the output changes:
% perl -MFoo -e 'Foo::foo()'
0
Note that the line that was commented out should do nothing, because
it ends with the conditional qualifier "if 0". Therefore, this
line is essentially a no-op and should have absolutely no effect
on the execution of this code.
I'm seeing this behavior with v. 5.8.8. Does anyone see it also
with more recent versions?
I have no doubt that this is a bug, but I can't begin to figure
out why it's happening. Any light that may be thrown on this puzzle
would be much appreciated.
Also, is there a better solution to this problem than including
silly "voodoo code" like the first line in Foo::foo?
TIA!
Kynn