my ($x, $y, $z) = (1, 2, 3);
say "sorted backward" if ++$x > ++$y > ++$z;
Will $z be incremented even though the chained comparison is known to be
false after ++$x and ++$y are compared?
Joe Gottman
I don't see a reason for chained comparisons not to short-circuit,
besides the surprise factor. But anyone who knows about &&, and
understands chained comparisons as expanding to &&, should understand
short-circuiting behavior.
Luke
$x++; $y++; $z++;
say "sorted backward" if $x > $y > $z;
To be honest, in this example it mostly doesn't matter; if $x > $y, then
($x+1) > ($y+1). But in many quickly written scripts I did some numeric
operation to force the value to numeric, even if I got a parameter like
"string" (which becomes 0 when numyfied)
How about some flag saying "don't short-circuit this"?
Regards,
Phil