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