in reply to Re^2: adding/subtracting calender dates
in thread adding/subtracting calender dates

FYI - xor is an "exclusive or". It has the following rules:
(1 xor 1) == 0 (1 xor 0) == 1 (0 xor 1) == 1 (0 xor 0) == 0 (0 xor 1 xor 1) == 0 (0 xor 1 xor 0) == 1 etc etc
Meaning that it will return true if and only if exactly 1 of the xor'd variables returns true.

Replies are listed 'Best First'.
Re: xor =
by fishbot_v2 (Chaplain) on Jun 02, 2005 at 22:28 UTC

    Close, but not quite. Try this for example:

    print "foo" if (1 xor 1 xor 1);

    prints foo, since

    (1 xor 1 xor 1) == ((1 xor 1) xor 1) == ( ( 0 ) xor 1 ) == 1

    In general terms, xor actually returns true if an odd number of true values exist in the set. In the cases where the set is of size two, this means exactly one truth. That doesn't generalize, though.

    addendum: In the OPs case, though, it worked because his alternatives were all mutually exclusive. However, since xor can't shortcircuit, it took a lot longer to work than a normal or.