The first two forms explicitly list each variable only once:
The second two forms require each variable to be listed twice:my $only_one = 1 == ($x ? 1 : 0) + ($y ? 1 : 0) + ($z ? 1 :0); + my $only_one = 2 == (! $x) + (! $y) + (! $z);
Just based on this criterion, I'd avoid the 2nd pair of solutions. (Looking at other replies, those with sub, map, grep, or List:Utils will take a list -- easier to maintain.)my $only_one = ($x || $y || $z) && (! ($x && $y)) && (! ($y && $z)) && + (! ($z && $x)); my $only_one = (! ($x && $y && $z)) && ($x ^ $y ^ $z);
-QM
--
Quantum Mechanics: The dreams stuff is made of
In reply to Re^2: One out of three ain't bad
by QM
in thread One out of three ain't bad
by saintmike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |