Had to think a little while to figure out the right way to produce a URL from a CGI program pointing to the same program with a parameter added/changed/overridden. I started out appending the parameter, then realized instead I needed to instead change it if it already existed in the middle, and wondered for a bit what the "right way" to do this was (i.e., most robust and using a module).
It's taking me a little while to get back into the swing of things with CGI, and I'm surprised. It's been about a year since I wrote a CGI program on the job.
my($cgi, %newparams) = @_:
my $newcgi = CGI->new($cgi);
foreach my $param (keys %newparams)
return $newcgi->url(-relative => 1, query => 1);
One thing I consider an oddity is that CGI.pm apparently prefers ; to & in query strings. That seems weird to me; while the CGI standard needlessly defines lots of alternatives, it seems like CGI.pm should go with what most people use.
Another oddity is that the CGI.pm documentation says you can get the "unprocessed query string" with the query_string method, but you're obviously getting a processed and regenerated query string because it will replace your ampersands with semicolons.