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.
|