in reply to Quick Regex Question

s/([^\w-])/'%'.unpack("H*", $1)/eg; # %5e%25%40%7cCaD5H
See perlre, pack and unpack. If you need to use another character besides '%', go for it.

Replies are listed 'Best First'.
Re: Re: Quick Regex Question
by Anonymous Monk on Feb 08, 2001 at 00:19 UTC
    Thanks. I got it working both ways.. works great.
    What does the e do? ( .. ("H*", $1)/eg; )

    I didn't see it in perlre.
    tia

      It turns out that /e is not documented in perlre because /e does not affect the regular expression. Instead, /e is documented in perlop, in the documentation for s/// (near the bottom).
      Odd; I can't find it documented either. Its purpose is to tell Perl to evaluate the right-hand-side of a substitution, instead of just using it as-is. This lets you put code in the right-hand-side of a substitution instead of just text.