July 15th, 2006

perl urlencode without libs

$url = “Foo bar com.dx?q=23″;
$url =~ s/([^\w\-\.\@])/$1 eq ” “?”+”:
sprintf(”%%%2.2x”,ord($1))/eg;

print $url;

I don’t remember where I got this, but it must have come in handy for me at some point. Never hurts to have this kind of stuff laying around, just in case.

One Response to “perl urlencode without libs”

  1. ClintJCL Says:

    I think I may already have something like this in my Clint::whatever libraries.. but man.. I’m totally saving that snippet into my perl-NOTES.txt file :)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>