Ano-Tech Computers
Enter keyword:

How to URL encode a string in Perl
Problem:
When passing "weird" characters in web forms, URLs etc. the HTTP standard requires them to be encoded as hex ASCII codes with leading % signs. Example: "my fun stuff" = "my%20fun%20stuff"
 
Solution:
Cast this regular expression on your string to encode it:

$string =~ s/([^A-Za-z0-9\.])/sprintf("%%%02X", ord($1))/seg;
 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles