Hello all...

I'm working on a kind of Rube Goldberg-ish series of CGI scripts, each of which needs to create web pages which in turn pass variables along to other scripts via A HREF="..." fields. (In other words, I'm passing hidden state parameters in links.)

Question: is there a good way of building up a query string with escaped names and values? I'm finding myself having to write routines such as:

my $query_str = join('&', map("@{[CGI->escape($_)]}=@{[CGI->escape(par +am($_))]}", qw(foo bar baz)); print "http://www.foo.com/cgi-bin/foo.pl?$query_str";
But this gets old fairly quickly. I'd prefer to do something like this:
my $uri_query = URI::Query->new('http://www.foo.com/cgi-bin/foo.pl'); foreach ( qw( foo bar baz ) ) { $uri_query->set_param($_, param($_)); } print $uri_query->as_string();
The regular URI object will let me set the query string-- but won't let me do parameter-by-parameter stuff. The CGI module will let me use the object-oriented interface to create and alter a blank query-- but seems to use semicolons as delimiters, which has caused problems in "Refresh" headers. (When standards collide!)

I could either continue writing custom routines all the time, or I could write a simple module to handle building the query. My question is: is there anything out there already that handles this? It's such a common thing to do that there must be an easy solution that I'm missing.

Much appreciation...

stephen


In reply to Best way of doing CGI passthroughs by stephen

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.