in reply to Anyone use "xor" in conditionals?

On at least two occasions (but not very many more than that) I've written code like:

if( !$a == !$b ) { #or if( !$x != !$y ) {
and those could now be rewritten:
if( not $a xor $b ) { #or if( $x xor $y ) {
but I don't adopt new Perl features lightly and I haven't written Perl code that wanted that sort of test since I noticed the existance of xor so I've never used xor, just written code where I would have used it had it been available enough at the time.

Though, I actually find the concept of "these two logical expressions are equal" to be more useful/natural than a logical "xor" (not equal) so I'm more likely to want

if( !$a == !$b ) {
than the other case and I'd probably leave that as-is rather than change it to
if( not $a xor $b ) {
because I find the latter harder to understand. So I'd probably rather have an eqv (pronounced "equivalent") over an xor. (:

                - tye

Replies are listed 'Best First'.
Re: Re: Anyone use "xor" in conditionals? (yes/no)
by demerphq (Chancellor) on Jul 14, 2003 at 09:16 UTC

    On at least two occasions (but not very many more than that) I've written code like:

    Heh. In my test code I use the syntax you've shown quite regularly. I was unaware that xor did the right thing with undef and hence have used the !$x == !$y or !$x != !$y syntax fairly often.

    And I also agree with you that I prefer this syntax to xor as it to me makes the intent of the test easier to see.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...