Skip to content

Commit cf8bea5

Browse files
committed
perlop: Move discussion into proper sections
This detail for two sections was combined in a whole other section. This splits the detail into text appropriate for each section to which it applies, and moves it there.
1 parent 6283f1e commit cf8bea5

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

pod/perlop.pod

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,12 @@ if the left operand is false, the right operand is not even evaluated.
10251025
Scalar or list context propagates down to the right operand if it
10261026
is evaluated.
10271027

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+
10281034
=head2 C-style Logical Or
10291035
X<||> X<operator, logical, or>
10301036

@@ -1033,6 +1039,29 @@ if the left operand is true, the right operand is not even evaluated.
10331039
Scalar or list context propagates down to the right operand if it
10341040
is evaluated.
10351041

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+
10361065
=head2 C-style Logical Xor
10371066
X<^^> X<operator, logical, xor>
10381067

@@ -1072,29 +1101,6 @@ for selecting between two aggregates for assignment:
10721101
@a = scalar(@b) || @c; # because it really means this.
10731102
@a = @b ? @b : @c; # This works fine, though.
10741103

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-
10981104
=head2 Range Operators
10991105
X<operator, range> X<range> X<..> X<...>
11001106

0 commit comments

Comments
 (0)