diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-11-25 14:50:48 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-11-27 07:05:04 -0800 |
commit | d78f32f607952d58a998c5b7554572320dc57b2a (patch) | |
tree | 73fac57f0e79e1b542357b4935cf4480ba397748 /pod | |
parent | 20961b6483f3653e3bf928a60cca828e2b13e098 (diff) | |
download | perl-d78f32f607952d58a998c5b7554572320dc57b2a.tar.gz |
Update docs to concur with $`,$&,$' changes
plus a couple of other pod tweaks.
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlre.pod | 19 | ||||
-rw-r--r-- | pod/perlreref.pod | 8 | ||||
-rw-r--r-- | pod/perlretut.pod | 12 | ||||
-rw-r--r-- | pod/perlvar.pod | 32 |
4 files changed, 47 insertions, 24 deletions
diff --git a/pod/perlre.pod b/pod/perlre.pod index 59a8abe70a..76b811383d 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -91,6 +91,9 @@ X</p> X<regex, preserve> X<regexp, preserve> Preserve the string matched such that ${^PREMATCH}, ${^MATCH}, and ${^POSTMATCH} are available for use after matching. +In Perl 5.18 and higher this is ignored. ${^PREMATCH}, ${^MATCH}, and +${^POSTMATCH} will be available after the match regardless of the modifier. + =item g and c X</g> X</c> @@ -871,9 +874,11 @@ B<NOTE>: Failed matches in Perl do not reset the match variables, which makes it easier to write code that tests for a series of more specific cases and remembers the best match. -B<WARNING>: Once Perl sees that you need one of C<$&>, C<$`>, or +B<WARNING>: If your code is to run on Perl 5.16 or earlier, +beware that once Perl sees that you need one of C<$&>, C<$`>, or C<$'> anywhere in the program, it has to provide them for every -pattern match. This may substantially slow your program. Perl +pattern match. This may substantially slow your program. (In Perl 5.18 a +more efficient mechanism is used, eliminating any slowdown.) Perl uses the same mechanism to produce C<$1>, C<$2>, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the @@ -882,19 +887,17 @@ use C<$&>, C<$`> or C<$'>, then patterns I<without> capturing parentheses will not be penalized. So avoid C<$&>, C<$'>, and C<$`> if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've -already paid the price. As of 5.17.4, the presence of each of the three -variables in a program is recorded separately, and depending on -circumstances, perl may be able be more efficient knowing that only C<$&> -rather than all three have been seen, for example. +already paid the price. X<$&> X<$`> X<$'> -As a workaround for this problem, Perl 5.10.0 introduces C<${^PREMATCH}>, +As a workaround for this problem, Perl 5.10.0 introduced C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}>, which are equivalent to C<$`>, C<$&> and C<$'>, B<except> that they are only guaranteed to be defined after a successful match that was executed with the C</p> (preserve) modifier. The use of these variables incurs no global performance penalty, unlike their punctuation char equivalents, however at the trade-off that you -have to tell perl when you want to use them. +have to tell perl when you want to use them. As of Perl 5.18, these three +variables are equivalent to C<$`>, C<$&> and C<$'>, and C</p> is ignored. X</p> X<p modifier> =head2 Quoting metacharacters diff --git a/pod/perlreref.pod b/pod/perlreref.pod index 954a423759..83c1316168 100644 --- a/pod/perlreref.pod +++ b/pod/perlreref.pod @@ -275,13 +275,15 @@ There is no quantifier C<{,n}>. That's interpreted as a literal string. ${^MATCH} Entire matched string ${^POSTMATCH} Everything after to matched string +Note to those still using Perl 5.16 or earlier: The use of C<$`>, C<$&> or C<$'> will slow down B<all> regex use -within your program. Consult L<perlvar> for C<@-> -to see equivalent expressions that won't cause slow down. -See also L<Devel::SawAmpersand>. Starting with Perl 5.10, you +within your program. Consult L<perlvar> for C<@-> +to see equivalent expressions that won't cause slowdown. +See also L<Devel::SawAmpersand>. Starting with Perl 5.10, you can also use the equivalent variables C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}>, but for them to be defined, you have to specify the C</p> (preserve) modifier on your regular expression. +In Perl 5.18, the use of C<$`>, C<$&> and C<$'> makes no speed difference. $1, $2 ... hold the Xth captured expr $+ Last parenthesized pattern match diff --git a/pod/perlretut.pod b/pod/perlretut.pod index bf4ab3bc29..11ad1f64a3 100644 --- a/pod/perlretut.pod +++ b/pod/perlretut.pod @@ -900,7 +900,10 @@ of the string after the match. An example: In the second match, C<$`> equals C<''> because the regexp matched at the first character position in the string and stopped; it never saw the -second 'the'. It is important to note that using C<$`> and C<$'> +second 'the'. + +If your code is to run on Perl versions earlier than +5.18, it is worthwhile to note that using C<$`> and C<$'> slows down regexp matching quite a bit, while C<$&> slows it down to a lesser extent, because if they are used in one regexp in a program, they are generated for I<all> regexps in the program. So if raw @@ -913,8 +916,11 @@ C<@+> instead: $' is the same as substr( $x, $+[0] ) As of Perl 5.10, the C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}> -variables may be used. These are only set if the C</p> modifier is present. -Consequently they do not penalize the rest of the program. +variables may be used. These are only set if the C</p> modifier is +present. Consequently they do not penalize the rest of the program. In +Perl 5.18, C<${^PREMATCH}>, C<${^MATCH}> and C<${^POSTMATCH}> are available +whether the C</p> has been used or not (the modifier is ignored), and +C<$`>, C<$'> and C<$&> do not cause any speed difference. =head2 Non-capturing groupings diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 449f3f5c1b..2ce9e3be3a 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -780,7 +780,7 @@ we have not made another match: $1 is Mutt; $2 is Jeff $1 is Wallace; $2 is Grommit -Due to an unfortunate accident of Perl's implementation, C<use +If you are using Perl v5.16 or earlier, note that C<use English> imposes a considerable performance penalty on all regular expression matches in a program because it uses the C<$`>, C<$&>, and 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 C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables instead so you only suffer the performance penalties. +If you are using Perl v5.18.0 or higher, you do not need to worry about +this, as the three naughty variables are no longer naughty. + =over 8 =item $<I<digits>> ($1, $2, ...) @@ -819,7 +822,8 @@ The string matched by the last successful pattern match (not counting any matches hidden within a BLOCK or C<eval()> enclosed by the current BLOCK). -The use of this variable anywhere in a program imposes a considerable +In Perl v5.16 and earlier, the use of this variable +anywhere in a program imposes a considerable performance penalty on all regular expression matches. To avoid this penalty, you can extract the same substring by using L</@->. Starting 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. X<${^MATCH}> This is similar to C<$&> (C<$MATCH>) except that it does not incur the -performance penalty associated with that variable, and is only guaranteed +performance penalty associated with that variable. +In Perl v5.16 and earlier, it is only guaranteed to return a defined value when the pattern was compiled or executed with -the C</p> modifier. +the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so +C<${^MATCH}> does the same thing as C<$MATCH>. This variable was added in Perl v5.10.0. @@ -850,7 +856,8 @@ The string preceding whatever was matched by the last successful pattern match, not counting any matches hidden within a BLOCK or C<eval> enclosed by the current BLOCK. -The use of this variable anywhere in a program imposes a considerable +In Perl v5.16 and earlier, the use of this variable +anywhere in a program imposes a considerable performance penalty on all regular expression matches. To avoid this penalty, you can extract the same substring by using L</@->. Starting 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. X<$`> X<${^PREMATCH}> This is similar to C<$`> ($PREMATCH) except that it does not incur the -performance penalty associated with that variable, and is only guaranteed +performance penalty associated with that variable. +In Perl v5.16 and earlier, it is only guaranteed to return a defined value when the pattern was compiled or executed with -the C</p> modifier. +the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so +C<${^PREMATCH}> does the same thing as C<$PREMATCH>. This variable was added in Perl v5.10.0 @@ -886,7 +895,8 @@ enclosed by the current BLOCK). Example: /def/; print "$`:$&:$'\n"; # prints abc:def:ghi -The use of this variable anywhere in a program imposes a considerable +In Perl v5.16 and earlier, the use of this variable +anywhere in a program imposes a considerable performance penalty on all regular expression matches. To avoid this penalty, you can extract the same substring by 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. X<${^POSTMATCH}> X<$'> X<$POSTMATCH> This is similar to C<$'> (C<$POSTMATCH>) except that it does not incur the -performance penalty associated with that variable, and is only guaranteed +performance penalty associated with that variable. +In Perl v5.16 and earlier, it is only guaranteed to return a defined value when the pattern was compiled or executed with -the C</p> modifier. +the C</p> modifier. In Perl v5.18, the C</p> modifier does nothing, so +C<${^POSTMATCH}> does the same thing as C<$POSTMATCH>. This variable was added in Perl v5.10.0. |