Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
X() provides a reference to the its $x, and $x increases from 1,2,3, etc. But funny things happen when I have two X()'s in one statement. Sometimes it evaluates the two independently, so I get two different values, but sometimes it evaluates both of them to the same value. The output is:use strict; use warnings; { my $x = 0; sub X() { ++$x; \$x; } } print ${X()}, "\n"; print ${X()}, "\n"; print ${X()}, "\n"; print ${X()}, "\n"; print "${X()}${X()}\n"; # why does this behave print "${X()} ${X()}\n"; # differently from this?
What I can't explain is why the last two outputs have different values, since the only difference between them is the addition of a space in the string.1 2 3 4 66 <--- why is this not 56? 7 8 <--- or why is this not 8 8?
|
---|