http://www.perlmonks.org?node_id=733329


in reply to Re^3: Burned by precedence rules (== true)
in thread Burned by precedence rules

I'm sure i shouldnt say this, but more than once I have written

if ( !$x == !$y ) { ... } if ( !$x != !$y ) { ... }

which I think is a fair exception to your rule. I kinda view ! and !! as "boolean constructors", and so long as both sides of your (in)equality are guaranteed to be a "boolean" obtained one of these constructors you can compare them.

But I'm really just nit-picking. :-)

---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^5: Burned by precedence rules (== true)
by ikegami (Patriarch) on Dec 30, 2008 at 20:09 UTC

    There's a logical operator for that: xor

    if ( !$x == !$y) ) # bool($x) == bool($y) if ( !$x != !$y ) # bool($x) != bool($y)
    can be written as
    if ( !($x xor $y) ) # bool($x) == bool($y) if ( $x xor $y ) # bool($x) != bool($y)

    Unforunately, both sets have readability issues.

      In Perl 6 we can use positive boolean context, which helps readability a little:
      if ?$x == ?$y {...} if ?$x != ?$y {...}
      We can use junctions, which again helps the different case more than the same case:
      if not $x ^ $y {...} if $x ^ $y {...}
      or if you prefer:
      if !one($x,$y) {...} if one($x,$y) {...}
      That's probably enough ways to do it...

        Nah. Clearly this demonstrates the utility of a few "Boolean comparison" operators:

        if $isFree ?= $isEasy if $isOne !?= $isOther unlink $dev eqv unlink $prod or die "Inconsistent state"; system $verifyUser neqv system $verifyAdmin or die "You are not just either a User or an Admin";

        ;)

        - tye        

      Ah yes, scalar xor, i always forget about it. Personally the !$x == !$y makes more sense to me than !($x xor $y). But whatever.

      ---
      $world=~s/war/peace/g