in reply to Character conversion

If you insist on rolling your own, something like this:
$url_string =~ s/([^[:alnum:]])/sprintf '%%%02x', ord($1)/eg; # thanks + for the 02, ikegami
but it's probably better to find a module like URI::Escape.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Character conversion
by ikegami (Patriarch) on Feb 22, 2006 at 17:43 UTC

    That should be %02x, not %x, or else it will fail for "\x0" to "\xF".

    One reason URI::Escape is better is because it fails safely when provided with unicode characters, while your code fails badly.

Re^2: Character conversion
by Anonymous Monk on Feb 22, 2006 at 17:11 UTC
    Thanks,
    This was exactly what I needed..