in reply to Re^4: Order of evaluation/interpolation of references
in thread Order of evaluation/interpolation of references
There are good reasons why some languages work hard on being side-effect free.
X() has side-effects causing problems and I have problems imagining any practical application of this pattern.
Or could you show me a reason to return the reference of the same static closure variable instead of the value itself?
>that it produces the wrong result,
sorry but which behavior is wrong and which is right? That's highly debatable.
UPDATE:
As you can see from the following code, Y() is always executed after X(), the problem is only in the timing of variable interpolation.
and this only in conjunction of the highly disputable trick, to inject code execution by dereferencing. (IMHO allowing this is a design weakness)
use 5.010; { my $x; sub X { say "X"; $x = shift; \$x; } sub Y { say "Y"; $x = shift; \$x; } } say "${X(1)}${Y(2)}"; say "${X(1)} ${Y(2)}";
OUTPUT:
X Y 22 X Y 1 2
Cheers Rolf
|
---|