On Thursday 19 January 2006 04:25, Luke Palmer wrote: > On 1/19/06, Joe Gottman <[EMAIL PROTECTED]> wrote: > > Suppose I have code that looks like this: > > > > 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? > > 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. Although that may lead to _longer_ code, which (when extended) is likely to be broken:
$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