I think you are just trying to construct the query segment of a URI, probably for a GET request. You probably intend to attach it to a base URI. May as well do both at the same time:
You could use a URI object:
use URI; my %params = ( name => 'josh', age => 26 ); my $uri = URI->new('http://www.example.com'); $uri->query_form(%params); print "$uri\n"; __END__ __OUTPUT__ http://www.example.com?name=josh&age=26
Or you could construct the query param list without attaching it to a base URI by using URI::QueryParam like this:
use URI::QueryParam; use URI; my %params = ( name => 'josh', age => 26 ); my $u = URI->new; $u->query_param($_, $params{$_}) for keys %params; print $u->query, "\n"; __END__ __OUTPUT__ name=josh&age=26
Either construct handles proper escaping of embedded metacharacters for you automatically. And both of these examples use components of the same URI distribution, on CPAN.
Dave
In reply to Re: url escape
by davido
in thread url escape
by bigup401
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |