@@ -780,7 +780,7 @@ we have not made another match:
780
780
$1 is Mutt; $2 is Jeff
781
781
$1 is Wallace; $2 is Grommit
782
782
783
- Due to an unfortunate accident of Perl's implementation, C<use
783
+ If you are using Perl v5.16 or earlier, note that C<use
784
784
English> imposes a considerable performance penalty on all regular
785
785
expression matches in a program because it uses the C<$`>, C<$&>, and
786
786
C<$'>, regardless of whether they occur in the scope of C<use
@@ -797,6 +797,9 @@ Since Perl v5.10.0, you can use the C</p> match operator flag and the
797
797
C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables instead
798
798
so you only suffer the performance penalties.
799
799
800
+ If you are using Perl v5.18.0 or higher, you do not need to worry about
801
+ this, as the three naughty variables are no longer naughty.
802
+
800
803
=over 8
801
804
802
805
=item $<I<digits>> ($1, $2, ...)
@@ -819,7 +822,8 @@ The string matched by the last successful pattern match (not counting
819
822
any matches hidden within a BLOCK or C<eval()> enclosed by the current
820
823
BLOCK).
821
824
822
- The use of this variable anywhere in a program imposes a considerable
825
+ In Perl v5.16 and earlier, the use of this variable
826
+ anywhere in a program imposes a considerable
823
827
performance penalty on all regular expression matches. To avoid this
824
828
penalty, you can extract the same substring by using L</@->. Starting
825
829
with Perl v5.10.0, you can use the C</p> match flag and the C<${^MATCH}>
@@ -833,9 +837,11 @@ Mnemonic: like C<&> in some editors.
833
837
X<${^MATCH}>
834
838
835
839
This is similar to C<$&> (C<$MATCH>) except that it does not incur the
836
- performance penalty associated with that variable, and is only guaranteed
840
+ performance penalty associated with that variable.
841
+ In Perl v5.16 and earlier, it is only guaranteed
837
842
to return a defined value when the pattern was compiled or executed with
838
- the C</p> modifier.
843
+ the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
844
+ C<${^MATCH}> does the same thing as C<$MATCH>.
839
845
840
846
This variable was added in Perl v5.10.0.
841
847
@@ -850,7 +856,8 @@ The string preceding whatever was matched by the last successful
850
856
pattern match, not counting any matches hidden within a BLOCK or C<eval>
851
857
enclosed by the current BLOCK.
852
858
853
- The use of this variable anywhere in a program imposes a considerable
859
+ In Perl v5.16 and earlier, the use of this variable
860
+ anywhere in a program imposes a considerable
854
861
performance penalty on all regular expression matches. To avoid this
855
862
penalty, you can extract the same substring by using L</@->. Starting
856
863
with Perl v5.10.0, you can use the C</p> match flag and the
@@ -865,9 +872,11 @@ Mnemonic: C<`> often precedes a quoted string.
865
872
X<$`> X<${^PREMATCH}>
866
873
867
874
This is similar to C<$`> ($PREMATCH) except that it does not incur the
868
- performance penalty associated with that variable, and is only guaranteed
875
+ performance penalty associated with that variable.
876
+ In Perl v5.16 and earlier, it is only guaranteed
869
877
to return a defined value when the pattern was compiled or executed with
870
- the C</p> modifier.
878
+ the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
879
+ C<${^PREMATCH}> does the same thing as C<$PREMATCH>.
871
880
872
881
This variable was added in Perl v5.10.0
873
882
@@ -886,7 +895,8 @@ enclosed by the current BLOCK). Example:
886
895
/def/;
887
896
print "$`:$&:$'\n"; # prints abc:def:ghi
888
897
889
- The use of this variable anywhere in a program imposes a considerable
898
+ In Perl v5.16 and earlier, the use of this variable
899
+ anywhere in a program imposes a considerable
890
900
performance penalty on all regular expression matches.
891
901
To avoid this penalty, you can extract the same substring by
892
902
using L</@->. Starting with Perl v5.10.0, you can use the C</p> match flag
@@ -901,9 +911,11 @@ Mnemonic: C<'> often follows a quoted string.
901
911
X<${^POSTMATCH}> X<$'> X<$POSTMATCH>
902
912
903
913
This is similar to C<$'> (C<$POSTMATCH>) except that it does not incur the
904
- performance penalty associated with that variable, and is only guaranteed
914
+ performance penalty associated with that variable.
915
+ In Perl v5.16 and earlier, it is only guaranteed
905
916
to return a defined value when the pattern was compiled or executed with
906
- the C</p> modifier.
917
+ the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so
918
+ C<${^POSTMATCH}> does the same thing as C<$POSTMATCH>.
907
919
908
920
This variable was added in Perl v5.10.0.
909
921
0 commit comments