Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Re: Make a string regexp-safe

by IlyaM (Parson)
on Jul 14, 2002 at 18:50 UTC ( [id://181627]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Make a string regexp-safe
in thread Make a string regexp-safe

It is very ugly and it is not very error prone (who knows what changes in regexp syntax can be expected in perl 5.10.0). It is better either to use already mentioned quotemeta or to escape string with \Q and \E in regexp. Example:
my $string = "some unsafe chars"; .... =~ /\Q$string\E/;
It is exactly equivalent to
my $string = "some unsafe chars"; my $temp = quotemeta $string; .... =~ /$temp/;
See perlre for more info.

--
Ilya Martynov (http://martynov.org/)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found