How to Avoid Making Mountains while Escaping Special Characters
You want to match this; http://language.perl.com/faq/ . That's a real
(useful) URL by the way. Hint. To match it, you need to do this:
/http:\/\/language\.perl\.com\/faq\//;
which should make the awful metaphor above clearer, if not
funnier. The slash, / , is not
normally a metacharacter but as it is being used for the regular expression
delimiters, it needs to be escaped. We already know that . is special.
Fortunately for our eyes, Perl allows you to pick your delimiter if you prefix it with
'm' as this example shows. We'll use a #:
m#http://language\.perl\.com/faq/#;
Which is a huge improvement, as we change / to # .
We can go further with readability by quoting everything:
m#\Qhttp://language.perl.com/faq/\E#;
The \Q escapes everything
up until \E or the regex delimiter (so
we don't really need the \E above). In this case #
will not be escaped, as it delimits the regex.
Someone once posted a question about this to the Perl-Win32-Users mailing list and I
was so intrigued about this apparently undocumented trick I spent the next twenty minutes
figuring it out by trial and error, and posted a reply. Next day I found lots of messages
telling the poster to read the manual because it was clearly documented. <face
colour='red' intensity='high'> My excuse was I didn't have the docs to hand....moral of
the story - RTFM and RTF FAQs !