Skip to content

Commit a98c31c

Browse files
author
E. Choroba
committed
fixup! Mention that the regex used by the empty m// is scoped
1 parent 811f26a commit a98c31c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pod/perlop.pod

+9-9
Original file line numberDiff line numberDiff line change
@@ -2056,15 +2056,15 @@ The bottom line is that using C</o> is almost never a good idea.
20562056

20572057
If the I<PATTERN> evaluates to the empty string, the last
20582058
I<successfully> matched regular expression in the current dynamic
2059-
scope is used instead. In this case, only the C<g> and C<c> flags on
2060-
the empty pattern are honored; the other flags are taken from the
2061-
original pattern. If no match has previously succeeded, this will
2062-
(silently) act instead as a genuine empty pattern (which will always
2063-
match). Using a user supplied string as a pattern has the risk that if
2064-
the string is empty that it triggers the "last successful match"
2065-
behavior, which can be very confusing. In such cases you are
2066-
recommended to replace C<m/$pattern/> with C<m/(?:$pattern)/> to avoid
2067-
this behavior.
2059+
scope is used instead (see also L<perlvar/Scoping Rules of Regex Variables>).
2060+
In this case, only the C<g> and C<c> flags on the empty pattern are
2061+
honored; the other flags are taken from the original pattern. If no
2062+
match has previously succeeded, this will (silently) act instead as a
2063+
genuine empty pattern (which will always match). Using a user supplied
2064+
string as a pattern has the risk that if the string is empty that it
2065+
triggers the "last successful match" behavior, which can be very
2066+
confusing. In such cases you are recommended to replace C<m/$pattern/>
2067+
with C<m/(?:$pattern)/> to avoid this behavior.
20682068

20692069
The last successful pattern may be accessed as a variable via
20702070
C<${^LAST_SUCCESSFUL_PATTERN}>. Matching against it, or the empty

pod/perlvar.pod

+1
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ documented as behaving otherwise. See the following section for more
967967
details.
968968

969969
=head3 Scoping Rules of Regex Variables
970+
X<Scoping Rules of Regex Variables>
970971

971972
Regular expression variables allow the programmer to access the state of
972973
the most recent I<successful> regex match in the current dynamic scope.

0 commit comments

Comments
 (0)