Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: logical Exclusive Or, xor

by Aristotle (Chancellor)
on Oct 14, 2002 at 13:51 UTC ( [id://205071]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://205071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found