In perl.git, the branch maint-5.12 has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/e263ec98c6f970ce129950e453f7643c317a26b2?hp=a29b8db30979b72bc2ca716b71fa05f0fe30420d>

- Log -----------------------------------------------------------------
commit e263ec98c6f970ce129950e453f7643c317a26b2
Author: Rafael Garcia-Suarez <[email protected]>
Date:   Mon May 3 15:38:57 2010 +0200

    Reinstate some documentation about quotemeta
    
    (that was removed in 8bdbc703cb0af3faf2163ebce618944c51f180a0)
    (cherry picked from commit 9702b155e486f017ed2d6a28ec16132482f38d90)
-----------------------------------------------------------------------

Summary of changes:
 pod/perlfunc.pod |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 3fabeb0..2df06f6 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -4373,6 +4373,32 @@ the C<\Q> escape in double-quoted strings.
 
 If EXPR is omitted, uses C<$_>.
 
+quotemeta (and C<\Q> ... C<\E>) are useful when interpolating strings into
+regular expressions, because by default an interpolated variable will be
+considered a mini-regular expression. For example:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    $sentence =~ s{$substring}{big bad wolf};
+
+Will cause C<$sentence> to become C<'The big bad wolf jumped over...'>.
+
+On the other hand:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    $sentence =~ s{\Q$substring\E}{big bad wolf};
+
+Or:
+
+    my $sentence = 'The quick brown fox jumped over the lazy dog';
+    my $substring = 'quick.*?fox';
+    my $quoted_substring = quotemeta($substring);
+    $sentence =~ s{$quoted_substring}{big bad wolf};
+
+Will both leave the sentence as is. Normally, when accepting string input from
+the user, quotemeta() or C<\Q> must be used.
+
 =item rand EXPR
 X<rand> X<random>
 

--
Perl5 Master Repository

Reply via email to