@@ -987,9 +987,13 @@ C<"experimental::bitwise"> category.
987
987
X<operator, bitwise, or> X<bitwise or> X<|> X<operator, bitwise, xor>
988
988
X<bitwise xor> X<^>
989
989
990
- Binary C<"|"> returns its operands ORed together bit by bit.
990
+ Binary C<"|"> returns its operands ORed together bit by bit. If both
991
+ corresponding bits are 0, the resulting bit is 0; if either is 1, the result is
992
+ 1.
991
993
992
- Binary C<"^"> returns its operands XORed together bit by bit.
994
+ Binary C<"^"> returns its operands XORed together bit by bit. If both
995
+ corresponding bits are 0 or both are 1, the resulting bit is 0; if just
996
+ one is 1, the result is 1.
993
997
994
998
Although no warning is currently raised, the results are not well
995
999
defined when these operations are performed on operands that aren't either
@@ -1488,14 +1492,12 @@ expressions. It's equivalent to C<&&> except for the very low
1488
1492
precedence. This means that it short-circuits: the right
1489
1493
expression is evaluated only if the left expression is true.
1490
1494
1491
- =head2 Logical or and Exclusive Or
1492
- X<operator, logical, or> X<operator, logical, xor>
1493
- X<operator, logical, exclusive or>
1494
- X<or> X<xor>
1495
+ =head2 Logical Or
1496
+ X<operator, logical, or> X<or>
1495
1497
1496
1498
Binary C<"or"> returns the logical disjunction of the two surrounding
1497
- expressions. It's equivalent to C<||> except for the very low precedence.
1498
- This makes it useful for control flow:
1499
+ expressions. It's equivalent to C<||> except for it having very low
1500
+ precedence. This makes it useful for control flow:
1499
1501
1500
1502
print FH $data or die "Can't write to FH: $!";
1501
1503
@@ -1517,11 +1519,22 @@ takes higher precedence.
1517
1519
1518
1520
Then again, you could always use parentheses.
1519
1521
1520
- Binary C<"xor"> returns the exclusive-OR of the two surrounding expressions.
1521
- It cannot short-circuit (of course).
1522
-
1523
1522
There is no low precedence operator for defined-OR.
1524
1523
1524
+ =head2 Logical Exclusive Or
1525
+ X<operator, logical, xor> X<operator, logical, exclusive or> X<xor>
1526
+
1527
+ Binary C<"xor"> returns the logical disjunction of the two surrounding
1528
+ expressions. That means it returns 1 if either, but not both, are true.
1529
+ It's equivalent to C<^> except for it having very low precedence. It
1530
+ tends to be used to verify that two mutually-exclusive conditions are
1531
+ actually mutually exclusive. For example, in Perl's test suite, we
1532
+ might want to test that a regular expression pattern can't both match
1533
+ and not match, for otherwise it would be a bug in our pattern matching
1534
+ code.
1535
+
1536
+ ($a =~ /$pat/ xor $a !~ /$pat/) or die;
1537
+
1525
1538
=head2 C Operators Missing From Perl
1526
1539
X<operator, missing from perl> X<&> X<*>
1527
1540
X<typecasting> X<(TYPE)>
0 commit comments