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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.