Skip to content

Commit 811f26a

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

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

pod/perlop.pod

+10-9
Original file line numberDiff line numberDiff line change
@@ -2055,15 +2055,16 @@ The bottom line is that using C</o> is almost never a good idea.
20552055
=item The empty pattern C<//>
20562056

20572057
If the I<PATTERN> evaluates to the empty string, the last
2058-
I<successfully> matched regular expression is used instead. In this
2059-
case, only the C<g> and C<c> flags on the empty pattern are honored; the
2060-
other flags are taken from the original pattern. If no match has
2061-
previously succeeded, this will (silently) act instead as a genuine
2062-
empty pattern (which will always match). Using a user supplied string as
2063-
a pattern has the risk that if the string is empty that it triggers the
2064-
"last successful match" behavior, which can be very confusing. In such
2065-
cases you are recommended to replace C<m/$pattern/> with
2066-
C<m/(?:$pattern)/> to avoid this behavior.
2058+
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.
20672068

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

0 commit comments

Comments
 (0)