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:
But this gets old fairly quickly. I'd prefer to do something like this: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";
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!)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();
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |