Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I escape quote marks? Specifically, I would like to replace each " with %22, i.e. $keyword =~(s/"/%22/g);

Replies are listed 'Best First'.
Re: Escaping quote marks
by theorbtwo (Prior) on Jan 29, 2002 at 03:24 UTC
Re: Escaping quote marks
by Ido (Hermit) on Jan 29, 2002 at 04:20 UTC
    The answer if sort of in the question. But if you meant you want something more genereal:
    s/(["'`])/'%'.unpack 'H*',$1/eg;
    Or for every not alphanum char (and not quotes only):
    s/(\W)/'%'.unpack 'H*',$1/eg;
    Or perhaps you only want it for chars that can't be in a URI:
    s/([^\w;\/?:\@&=\+\$,\[\]\-\.!~\*'\(\)])/'%'.unpack 'H*',$1/eg;