Skip to content

Commit b745da3

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 7238770 commit b745da3

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
@@ -1017,6 +1017,12 @@ if the left operand is false, the right operand is not even evaluated.
10171017
Scalar or list context propagates down to the right operand if it
10181018
is evaluated.
10191019

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+
10201026
=head2 C-style Logical Or
10211027
X<||> X<operator, logical, or>
10221028

@@ -1025,6 +1031,29 @@ if the left operand is true, the right operand is not even evaluated.
10251031
Scalar or list context propagates down to the right operand if it
10261032
is evaluated.
10271033

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+
10281057
=head2 C-style Logical Xor
10291058
X<^^> X<operator, logical, xor>
10301059

@@ -1064,29 +1093,6 @@ for selecting between two aggregates for assignment:
10641093
@a = scalar(@b) || @c; # because it really means this.
10651094
@a = @b ? @b : @c; # This works fine, though.
10661095

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-
10901096
=head2 Range Operators
10911097
X<operator, range> X<range> X<..> X<...>
10921098

0 commit comments

Comments
 (0)