in reply to Better Algorithm to Encode This?

You might be interested in something like this...
# Gleefully ripped from the CGI.pm escape method. $STRING =~ s/([^a-zA-Z0-9_.-])/lc sprintf(".%02x", ord($1))/eg; # Originally #$toencode =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x", ord($1))/eg;

Replies are listed 'Best First'.
Re: Re: Better Algorithm to Encode This?
by extremely (Priest) on Jun 13, 2001 at 05:54 UTC
    You'll need to encode the "." period for that to work correctly!!! (I couldn't help but golf it down a little, sorry.)
    ## No Period in the char class! $STRING =~ s/([^a-zA-Z0-9_-])/lc sprintf(".%02x", ord($1))/eg; ## my encode $S =~ s/([^\w-])/sprintf".%02x",ord$1/eg; ## my decode $S =~ s/\.(..)/chr hex $1/eg;

    --
    $you = new YOU;
    honk() if $you->love(perl)