in reply to Perlmonks Code Proxy

Always be cautious when using variables as a regexp: if it isn't protected with the \Q...\E sequence, you may be in big trouble. Your $basename var contains dots which are treated like if it were a regexp (Gee... If you understand what I say, you're good ;-)

$basename = 'http://www.perlmonks.org/'; $content =~ s!href="$basename!...
It will be interpreted as  $content=~ s!href="http://www.perl...
Use s!\Qhref="$basename...\E!\Q...\E! instead.
So it will be translated to s!href=http://www\.perl...

Replies are listed 'Best First'.
(Ovid) RE(2): Perlmonks Code Proxy
by Ovid (Cardinal) on Aug 19, 2000 at 07:57 UTC
    Sheesh. That's what I get for posting code too quickly. Fortunately, this hasn't caused a problem as I have used exclamation points as delimiters (and avoided the problem with the slashes) and the dot metacharacters match the actual dot characters. I got lucky! Thanks for pointing that out.

    This has actually caused me a problem with the $match variable as this will often contain characters that will have special meaning in a regex, but I can't simply wrap them in \Q and \E because of the problems with $ and @, so I'm going to write a short snippet that will handle that substitution for me, but this is turning out to be just a more difficult problem than I imagined!

    Cheers,
    Ovid

      If you want to have the variable contents being interpreted as a string literal rather than regex chars, the perlfunc:quotemeta function is useful.