Skip to content

Commit e1fd413

Browse files
committed
Revert "Update docs to concur with $`,$&,$' changes"
This reverts commit d78f32f. Since COW has now not been enabled by default for 5.18, revert the documentation changes which say that that $' etc no longer have a performance penalty, etc.
1 parent 1e1a634 commit e1fd413

File tree

4 files changed

+24
-47
lines changed

4 files changed

+24
-47
lines changed

pod/perlre.pod

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ X</p> X<regex, preserve> X<regexp, preserve>
9191
Preserve the string matched such that ${^PREMATCH}, ${^MATCH}, and
9292
${^POSTMATCH} are available for use after matching.
9393

94-
In Perl 5.18 and higher this is ignored. ${^PREMATCH}, ${^MATCH}, and
95-
${^POSTMATCH} will be available after the match regardless of the modifier.
96-
9794
=item g and c
9895
X</g> X</c>
9996

@@ -875,11 +872,9 @@ B<NOTE>: Failed matches in Perl do not reset the match variables,
875872
which makes it easier to write code that tests for a series of more
876873
specific cases and remembers the best match.
877874

878-
B<WARNING>: If your code is to run on Perl 5.16 or earlier,
879-
beware that once Perl sees that you need one of C<$&>, C<$`>, or
875+
B<WARNING>: Once Perl sees that you need one of C<$&>, C<$`>, or
880876
C<$'> anywhere in the program, it has to provide them for every
881-
pattern match. This may substantially slow your program. (In Perl 5.18 a
882-
more efficient mechanism is used, eliminating any slowdown.) Perl
877+
pattern match. This may substantially slow your program. Perl
883878
uses the same mechanism to produce C<$1>, C<$2>, etc, so you also pay a
884879
price for each pattern that contains capturing parentheses. (To
885880
avoid this cost while retaining the grouping behaviour, use the
@@ -888,17 +883,19 @@ use C<$&>, C<$`> or C<$'>, then patterns I<without> capturing
888883
parentheses will not be penalized. So avoid C<$&>, C<$'>, and C<$`>
889884
if you can, but if you can't (and some algorithms really appreciate
890885
them), once you've used them once, use them at will, because you've
891-
already paid the price.
886+
already paid the price. As of 5.17.4, the presence of each of the three
887+
variables in a program is recorded separately, and depending on
888+
circumstances, perl may be able be more efficient knowing that only C<$&>
889+
rather than all three have been seen, for example.
892890
X<$&> X<$`> X<$'>
893891

894-
As a workaround for this problem, Perl 5.10.0 introduced C<${^PREMATCH}>,
892+
As a workaround for this problem, Perl 5.10.0 introduces C<${^PREMATCH}>,
895893
C<${^MATCH}> and C<${^POSTMATCH}>, which are equivalent to C<$`>, C<$&>
896894
and C<$'>, B<except> that they are only guaranteed to be defined after a
897895
successful match that was executed with the C</p> (preserve) modifier.
898896
The use of these variables incurs no global performance penalty, unlike
899897
their punctuation char equivalents, however at the trade-off that you
900-
have to tell perl when you want to use them. As of Perl 5.18, these three
901-
variables are equivalent to C<$`>, C<$&> and C<$'>, and C</p> is ignored.
898+
have to tell perl when you want to use them.
902899
X</p> X<p modifier>
903900

904901
=head2 Quoting metacharacters

pod/perlreref.pod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,13 @@ There is no quantifier C<{,n}>. That's interpreted as a literal string.
275275
${^MATCH} Entire matched string
276276
${^POSTMATCH} Everything after to matched string
277277

278-
Note to those still using Perl 5.16 or earlier:
279278
The use of C<$`>, C<$&> or C<$'> will slow down B<all> regex use
280-
within your program. Consult L<perlvar> for C<@->
281-
to see equivalent expressions that won't cause slowdown.
282-
See also L<Devel::SawAmpersand>. Starting with Perl 5.10, you
279+
within your program. Consult L<perlvar> for C<@->
280+
to see equivalent expressions that won't cause slow down.
281+
See also L<Devel::SawAmpersand>. Starting with Perl 5.10, you
283282
can also use the equivalent variables C<${^PREMATCH}>, C<${^MATCH}>
284283
and C<${^POSTMATCH}>, but for them to be defined, you have to
285284
specify the C</p> (preserve) modifier on your regular expression.
286-
In Perl 5.18, the use of C<$`>, C<$&> and C<$'> makes no speed difference.
287285

288286
$1, $2 ... hold the Xth captured expr
289287
$+ Last parenthesized pattern match

pod/perlretut.pod

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,7 @@ of the string after the match. An example:
900900

901901
In the second match, C<$`> equals C<''> because the regexp matched at the
902902
first character position in the string and stopped; it never saw the
903-
second 'the'.
904-
905-
If your code is to run on Perl versions earlier than
906-
5.18, it is worthwhile to note that using C<$`> and C<$'>
903+
second 'the'. It is important to note that using C<$`> and C<$'>
907904
slows down regexp matching quite a bit, while C<$&> slows it down to a
908905
lesser extent, because if they are used in one regexp in a program,
909906
they are generated for I<all> regexps in the program. So if raw
@@ -916,11 +913,8 @@ C<@+> instead:
916913
$' is the same as substr( $x, $+[0] )
917914

918915
As of Perl 5.10, the C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}>
919-
variables may be used. These are only set if the C</p> modifier is
920-
present. Consequently they do not penalize the rest of the program. In
921-
Perl 5.18, C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}> are available
922-
whether the C</p> has been used or not (the modifier is ignored), and
923-
C<$`>, C<$'> and C<$&> do not cause any speed difference.
916+
variables may be used. These are only set if the C</p> modifier is present.
917+
Consequently they do not penalize the rest of the program.
924918

925919
=head2 Non-capturing groupings
926920

pod/perlvar.pod

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ we have not made another match:
783783
$1 is Mutt; $2 is Jeff
784784
$1 is Wallace; $2 is Grommit
785785

786-
If you are using Perl v5.16 or earlier, note that C<use
786+
Due to an unfortunate accident of Perl's implementation, C<use
787787
English> imposes a considerable performance penalty on all regular
788788
expression matches in a program because it uses the C<$`>, C<$&>, and
789789
C<$'>, regardless of whether they occur in the scope of C<use
@@ -800,9 +800,6 @@ Since Perl v5.10.0, you can use the C</p> match operator flag and the
800800
C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables instead
801801
so you only suffer the performance penalties.
802802

803-
If you are using Perl v5.18.0 or higher, you do not need to worry about
804-
this, as the three naughty variables are no longer naughty.
805-
806803
=over 8
807804

808805
=item $<I<digits>> ($1, $2, ...)
@@ -825,8 +822,7 @@ The string matched by the last successful pattern match (not counting
825822
any matches hidden within a BLOCK or C<eval()> enclosed by the current
826823
BLOCK).
827824

828-
In Perl v5.16 and earlier, the use of this variable
829-
anywhere in a program imposes a considerable
825+
The use of this variable anywhere in a program imposes a considerable
830826
performance penalty on all regular expression matches. To avoid this
831827
penalty, you can extract the same substring by using L</@->. Starting
832828
with Perl v5.10.0, you can use the C</p> match flag and the C<${^MATCH}>
@@ -840,11 +836,9 @@ Mnemonic: like C<&> in some editors.
840836
X<${^MATCH}>
841837

842838
This is similar to C<$&> (C<$MATCH>) except that it does not incur the
843-
performance penalty associated with that variable.
844-
In Perl v5.16 and earlier, it is only guaranteed
839+
performance penalty associated with that variable, and is only guaranteed
845840
to return a defined value when the pattern was compiled or executed with
846-
the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
847-
C<${^MATCH}> does the same thing as C<$MATCH>.
841+
the C</p> modifier.
848842

849843
This variable was added in Perl v5.10.0.
850844

@@ -859,8 +853,7 @@ The string preceding whatever was matched by the last successful
859853
pattern match, not counting any matches hidden within a BLOCK or C<eval>
860854
enclosed by the current BLOCK.
861855

862-
In Perl v5.16 and earlier, the use of this variable
863-
anywhere in a program imposes a considerable
856+
The use of this variable anywhere in a program imposes a considerable
864857
performance penalty on all regular expression matches. To avoid this
865858
penalty, you can extract the same substring by using L</@->. Starting
866859
with Perl v5.10.0, you can use the C</p> match flag and the
@@ -875,11 +868,9 @@ Mnemonic: C<`> often precedes a quoted string.
875868
X<$`> X<${^PREMATCH}>
876869

877870
This is similar to C<$`> ($PREMATCH) except that it does not incur the
878-
performance penalty associated with that variable.
879-
In Perl v5.16 and earlier, it is only guaranteed
871+
performance penalty associated with that variable, and is only guaranteed
880872
to return a defined value when the pattern was compiled or executed with
881-
the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
882-
C<${^PREMATCH}> does the same thing as C<$PREMATCH>.
873+
the C</p> modifier.
883874

884875
This variable was added in Perl v5.10.0
885876

@@ -898,8 +889,7 @@ enclosed by the current BLOCK). Example:
898889
/def/;
899890
print "$`:$&:$'\n"; # prints abc:def:ghi
900891

901-
In Perl v5.16 and earlier, the use of this variable
902-
anywhere in a program imposes a considerable
892+
The use of this variable anywhere in a program imposes a considerable
903893
performance penalty on all regular expression matches.
904894
To avoid this penalty, you can extract the same substring by
905895
using L</@->. Starting with Perl v5.10.0, you can use the C</p> match flag
@@ -914,11 +904,9 @@ Mnemonic: C<'> often follows a quoted string.
914904
X<${^POSTMATCH}> X<$'> X<$POSTMATCH>
915905

916906
This is similar to C<$'> (C<$POSTMATCH>) except that it does not incur the
917-
performance penalty associated with that variable.
918-
In Perl v5.16 and earlier, it is only guaranteed
907+
performance penalty associated with that variable, and is only guaranteed
919908
to return a defined value when the pattern was compiled or executed with
920-
the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
921-
C<${^POSTMATCH}> does the same thing as C<$POSTMATCH>.
909+
the C</p> modifier.
922910

923911
This variable was added in Perl v5.10.0.
924912

0 commit comments

Comments
 (0)