in reply to Anyone use "xor" in conditionals?

Not that I have anything really earth-shattering to add to what others have written, but just wanted to add another voice to the 'xor can be useful' crowd...

I used xor in the following situation:

There are 3 states, call them A, B, and Z, where the first 2 are sort of similar, and the last is different. I needed a conditional to test for the transition between (A or B) and Z (or vice versa). So instead of writing some monstrous thing like:

if ((($before eq 'A' || $before eq 'B') && $after eq 'Z') || ($before eq 'Z' && ($after eq 'A' || $after eq 'B'))) { # change from A|B <=> Z }
I simply wrote this:
if ($before eq 'Z' xor $after eq 'Z') { # change from A|B <=> Z }

I hope my explanation made sense... but that's my story of how I used xor...

Update: Upon further reflection, my non-xor conditional would be more simply and accurately written as one of these:

if (($before ne 'Z' && $after eq 'Z') || ($before eq 'Z' && $after ne 'Z')) { # change from A|B <=> Z } if (($before eq 'Z' || $after eq 'Z') && !($before eq 'Z' && $after eq 'Z')) { # change from A|B <=> Z }

... and that is equivalent to Abigail-II's summary of xor's logical equivalency:
if ((COND1 || COND2) && !(COND1 && COND2))

But I think it's still clear why xor is useful here, and perhaps I shed some light on a real-world usage... Not having looked at the source, but only bsb's post, I am guessing it's similar to the situation here:

/usr/local/lib/perl/5.6.1/DateTime.pm: if ( $self->{tz}->is_floatin +g xor $was_floating )

--
3dan