Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: How to prevent metacharacter interpolation

( #64364=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How to prevent metacharacter interpolation contributed by jmcnamara

Use either the quotemeta function:
$pattern = quotemeta( $pattern ); m/$pattern/;
or use the \Q and \E escape characters:
m/\Q$pattern\E/;
They do exactly the same thing; just one is a function and the other works inside regex patterns.

Comment on Answer: How to prevent metacharacter interpolation
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-08-22 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (157 votes), past polls