@@ -1017,14 +1017,19 @@ if the left operand is false, the right operand is not even evaluated.
1017
1017
Scalar or list context propagates down to the right operand if it
1018
1018
is evaluated.
1019
1019
1020
+ C<&&> returns the last value evaluated (unlike C's C<&&>, which returns
1021
+ 0 or 1).
1022
+
1020
1023
As an alternative to C<&&> when used for control flow, Perl provides the
1021
1024
C<and> operator (see L<below|/Logical And>).
1022
1025
The short-circuit behavior is identical. The precedence of C<"and"> is
1023
1026
much lower, however, so that you can safely use it after a list operator
1024
1027
without the need for parentheses.
1025
1028
1026
- =head2 C-style Logical Or
1029
+ =head2 C-style Logical Or, Xor, and Defined Or
1027
1030
X<||> X<operator, logical, or>
1031
+ X<^^> X<operator, logical, xor>
1032
+ X<//> X<operator, logical, defined-or>
1028
1033
1029
1034
Binary C<"||"> performs a short-circuit logical OR operation. That is,
1030
1035
if the left operand is true, the right operand is not even evaluated.
@@ -1054,16 +1059,10 @@ It would be even more readable to write that this way:
1054
1059
1055
1060
Using C<"or"> for assignment is unlikely to do what you want; see below.
1056
1061
1057
- =head2 C-style Logical Xor
1058
- X<^^> X<operator, logical, xor>
1059
-
1060
1062
Binary C<"^^"> performs a logical XOR operation. Both operands are
1061
1063
evaluated and the result is true only if exactly one of the operands is true.
1062
1064
Scalar or list context propagates down to the right operand.
1063
1065
1064
- =head2 Logical Defined-Or
1065
- X<//> X<operator, logical, defined-or>
1066
-
1067
1066
Although it has no direct equivalent in C, Perl's C<//> operator is related
1068
1067
to its C-style "or". In fact, it's exactly the same as C<||>, except that it
1069
1068
tests the left hand side's definedness instead of its truth. Thus,
@@ -1077,8 +1076,8 @@ cannot). This is very useful for
1077
1076
providing default values for variables. If you actually want to test if
1078
1077
at least one of C<$x> and C<$y> is defined, use S<C<defined($x // $y)>>.
1079
1078
1080
- The C<||>, C<// > and C<&& > operators return the last value evaluated
1081
- (unlike C's C<||> and C<&&>, which return 0 or 1). Thus, a reasonably
1079
+ The C<||>, C<^^ > and C<// > operators return the last value evaluated
1080
+ (unlike C's C<||> which returns 0 or 1). Thus, a reasonably
1082
1081
portable way to find out the home directory might be:
1083
1082
1084
1083
$home = $ENV{HOME}
@@ -3852,6 +3851,24 @@ Here is a short, but incomplete summary:
3852
3851
3853
3852
Choose wisely.
3854
3853
3854
+ =head2 C-style Logical Or
3855
+
3856
+ This section has been superceded by
3857
+ L</C-style Logical Or, Xor, and Defined Or>. The heading is retained
3858
+ only to prevent breaking any pre-existing links to it from outside.
3859
+
3860
+ =head2 C-style Logical Xor
3861
+
3862
+ This section has been superceded by
3863
+ L</C-style Logical Or, Xor, and Defined Or>. The heading is retained
3864
+ only to prevent breaking any pre-existing links to it from outside.
3865
+
3866
+ =head2 Logical Defined-Or
3867
+
3868
+ This section has been superceded by
3869
+ L</C-style Logical Or, Xor, and Defined Or>. The heading is retained
3870
+ only to prevent breaking any pre-existing links to it from outside.
3871
+
3855
3872
=head1 APPENDIX
3856
3873
3857
3874
=head2 List of Extra Paired Delimiters
0 commit comments