in reply to Evaluating the condition ($x)
My suspicion is that the answer may lie in the precedence of operators. The = seems to be evaluated first, and then the the ?: group second. Am I right?
We could confirm this by doing : $z = 1; $x = 1; $z = $x ? $z = 2 : $z *= 9; print $z;
Now, the output is not 1, it's not 9 but 18. How does it become 18? The fact that it's 18 seems to suggest that first the $z = 2 gets evaluated, and then immediately after that the $z *= 9 gets evaluated. (Note: the = sign and *= are on the same level of precedence.)
Edit: Another interesting code is $z = 1; print $z *= 2, $z *= 9; # This prints 1818 instead of 218
Edit: I thought I was onto something, but apparently not. I'm just even more lost now. I did this :
my $A = 1; my $B = 7; my $C = 5; my $D = 0; $D = $A ? $B *= 2 : $C *= 9; print "A=$A B=$B C=$C D=$D";
And the output is..... :drum roll:
A=1 B=126 C=5 D=126
Okay. I give up. I'm lost! Maybe we discovered a bug? How does $B become 126? Lol
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Evaluating the condition ($x ||= $y)
by syphilis (Archbishop) on Aug 26, 2024 at 03:46 UTC | |
by tybalt89 (Monsignor) on Aug 26, 2024 at 07:53 UTC | |
by ikegami (Patriarch) on Aug 26, 2024 at 04:14 UTC | |
by Anonymous Monk on Aug 26, 2024 at 09:31 UTC | |
by ikegami (Patriarch) on Aug 26, 2024 at 13:42 UTC |