in reply to Perl-CGI refresh with different param(s)??

self_url() just returns the url of the cgi script with the name/value pairs that the user entered into the form tacked onto the end of the url. So if self_url() returned this url:

"http://www.somesite.com/page1.htm?age=10&name=Tom"

You could do this:

my $url = self_url(); $url =~ s/name=Tom/name=Betty/; print $url, "\n"; --output:-- http://www.somesite.com/page1.htm?age=10&name=Betty

Then you could insert the altered url in the html output that you send back to the browser.

Replies are listed 'Best First'.
Re^2: Perl-CGI refresh with different param(s)??
by Your Mother (Archbishop) on Jun 20, 2011 at 21:09 UTC

    Altering URIs with regular expressions can get weird and break pretty fast. Something like this, using the modules I recommended earlier, is better-

    perl -MCGI=self_url -le 'print self_url' "o=hai;i=can;haz=cheezeburger +" http://localhost?o=hai;i=can;haz=cheezeburger perl -MCGI=self_url -MURI -MURI::QueryParam -le \ '$u = URI->new(self_url); $u->query_param(haz => "tacoz"); print $u' + \ "o=hai;i=can;haz=cheezeburger" http://localhost?o=hai;i=can;haz=tacoz