@@ -1017,6 +1017,12 @@ 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
+ As an alternative to C<&&> when used for control flow, Perl provides the
1021
+ C<and> operator (see L<below|/Logical And>).
1022
+ The short-circuit behavior is identical. The precedence of C<"and"> is
1023
+ much lower, however, so that you can safely use it after a list operator
1024
+ without the need for parentheses.
1025
+
1020
1026
=head2 C-style Logical Or
1021
1027
X<||> X<operator, logical, or>
1022
1028
@@ -1025,6 +1031,29 @@ if the left operand is true, the right operand is not even evaluated.
1025
1031
Scalar or list context propagates down to the right operand if it
1026
1032
is evaluated.
1027
1033
1034
+ As an alternative to C<||> when used for control flow, Perl provides the
1035
+ C<or> operator (L<see below|/Logical or and Exclusive Or>).
1036
+ The short-circuit behavior is identical. The precedence of C<"or"> is
1037
+ much lower, however, so that you can safely use it after a list operator
1038
+ without the need for parentheses:
1039
+
1040
+ unlink "alpha", "beta", "gamma"
1041
+ or gripe(), next LINE;
1042
+
1043
+ With the C-style operator that would have been written like this:
1044
+
1045
+ unlink("alpha", "beta", "gamma")
1046
+ || (gripe(), next LINE);
1047
+
1048
+ It would be even more readable to write that this way:
1049
+
1050
+ unless(unlink("alpha", "beta", "gamma")) {
1051
+ gripe();
1052
+ next LINE;
1053
+ }
1054
+
1055
+ Using C<"or"> for assignment is unlikely to do what you want; see below.
1056
+
1028
1057
=head2 C-style Logical Xor
1029
1058
X<^^> X<operator, logical, xor>
1030
1059
@@ -1064,29 +1093,6 @@ for selecting between two aggregates for assignment:
1064
1093
@a = scalar(@b) || @c; # because it really means this.
1065
1094
@a = @b ? @b : @c; # This works fine, though.
1066
1095
1067
- As alternatives to C<&&> and C<||> when used for
1068
- control flow, Perl provides the C<and> and C<or> operators (see below).
1069
- The short-circuit behavior is identical. The precedence of C<"and">
1070
- and C<"or"> is much lower, however, so that you can safely use them after a
1071
- list operator without the need for parentheses:
1072
-
1073
- unlink "alpha", "beta", "gamma"
1074
- or gripe(), next LINE;
1075
-
1076
- With the C-style operators that would have been written like this:
1077
-
1078
- unlink("alpha", "beta", "gamma")
1079
- || (gripe(), next LINE);
1080
-
1081
- It would be even more readable to write that this way:
1082
-
1083
- unless(unlink("alpha", "beta", "gamma")) {
1084
- gripe();
1085
- next LINE;
1086
- }
1087
-
1088
- Using C<"or"> for assignment is unlikely to do what you want; see below.
1089
-
1090
1096
=head2 Range Operators
1091
1097
X<operator, range> X<range> X<..> X<...>
1092
1098
0 commit comments