in reply to "Can't happen" bugs

I ran into this one not long ago:
if ($x = 0) { return "zero"; } elsif ($x < 0) { return "negative"; } elsif ($x > 0) { return "positive"; } # Cannot reach here

Replies are listed 'Best First'.
Re^2: "Can't happen" bugs
by jrockway (Acolyte) on Jan 18, 2007 at 23:47 UTC
    Beautiful! That's why you should always put the constant on the left:

    if(0 = $x) # Can't modify constant item in scalar assignment.

      Or use warnings:

      use warnings; my $x; if ($x = 0) { 1 } __END__ Found = in conditional, should be == at - line 4.

      lodin