in reply to logical Exclusive Or, xor

The results of an XOR always depend on both operands, so it always evaluates both and thus is useless as far as control flow is concerned. Using XOR is the same as just writing the operands separately if you're not interested in the result.

That code looks more like LISP than Perl if I may comment btw, and the first thing I'd do if I ran across it is rewrite. Use naked blocks, next and last in Perl, that's easier to read and just as efficient.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: logical Exclusive Or, xor
by Abigail-II (Bishop) on Oct 14, 2002 at 14:11 UTC
    I don't follow why xor is useless, and and isn't. Afterall, if I'm not interested in the result, I can write
    EXPR1 and EXPR2;
    as
    if (EXPR1) {EXPR2}

    And something similar for or.

    I've used xor, although not very often. A few months ago I used it in a program that took command line arguments. 2 options where multiple exclusive, but at least one of them had to be used. So I had something like:

    unless (defined ($opt1) xor defined ($opt2)) { die "usage message"; }

    I don't use xor often, but I still use it more than CGI.pm ;-).

    Abigail

      Afterall, if I'm not interested in the result, I can write EXPR1 and EXPR2; as if (EXPR1) {EXPR2}
      The former is what fruiture was doing. He was talking about shortcircuiting effects, after all. xor doesn't posess any.

      Makeshifts last the longest.