@@ -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
- 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:
1498
+ Logical C<"or"> returns the logical inclusive disjunction of the two
1499
+ surrounding expressions. It's equivalent to C<||> except for it having
1500
+ very low 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
+ Logical C<"xor"> returns the logical exclusive disjunction of the two
1528
+ surrounding expressions. That means it returns C<true> if either, but
1529
+ not both, are true. It's equivalent to C<^^> except for it having very
1530
+ low precedence. It tends to be used to verify that two
1531
+ mutually-exclusive conditions are actually mutually exclusive. For
1532
+ example, in Perl's test suite, we might want to test that a regular
1533
+ expression pattern can't both match and not match, for otherwise it
1534
+ would be a bug in our pattern matching code.
1535
+
1536
+ ($a =~ qr/$pat/ xor $a !~ qr/$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)>
@@ -3836,6 +3849,11 @@ Here is a short, but incomplete summary:
3836
3849
3837
3850
Choose wisely.
3838
3851
3852
+ =head2 Logical or and Exclusive Or
3853
+
3854
+ This section has been split into L</Logical Or> and
3855
+ L</Logical Exclusive Or>.
3856
+
3839
3857
=head1 APPENDIX
3840
3858
3841
3859
=head2 List of Extra Paired Delimiters
0 commit comments