![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
How can I quote a variable to use in a regexp?by faq_monk (Initiate) |
on Oct 08, 1999 at 00:25 UTC ( [id://663]=perlfaq nodetype: print w/replies, xml ) | Need Help?? |
Current Perl documentation can be found at perldoc.perl.org. Here is our local, out-dated (pre-5.6) version:
The Perl parser will expand
$string = "to die?"; $lhs = "die?"; $rhs = "sleep no more";
$string =~ s/Q$lhs/$rhs/; # $string is now "to sleep no more" Without the Q, the regexp would also spuriously match ``di''.
|
|