Takes all CGI parameters (both GET and POST data) and builds a query string to send as a GET request.
use CGI::Simple; # or use CGI; use URI::Escape; my $CGI = CGI::Simple->new; # or CGI->new; my $query = join( ';', map { uri_escape($_) . '=' . uri_escape($CGI->param($_)) } $CGI->param ); # now we can send a GET rquest somewhere $CGI->redirect('http://my.server.com/script.pl?' . $query);

Replies are listed 'Best First'.
Re: CGI query string from GET/POST data
by esskar (Deacon) on Feb 27, 2004 at 21:10 UTC
    it is much easier:
    package CGI; sub getparam { my ($self, $what) = @_; return $self->url_param($what) || $self->param($what); } 1;
    :)
Re: CGI query string from GET/POST data
by Hero Zzyzzx (Curate) on Feb 28, 2004 at 17:02 UTC
    Manually looping through the query parameters won't properly deal with the useful and common idiom of "multiple parameters with the same name" either. Let CGI handle it for you, it deals with multiple named parameters fine.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

    My Biz

Re: CGI query string from GET/POST data
by Anonymous Monk on Mar 02, 2004 at 23:17 UTC

    Fixed to permit multiple values to the same parameter name:

    use CGI::Simple; # or use CGI; use URI::Escape; my $CGI = CGI::Simple->new; # or CGI->new; my $query = join(';', map { my $k = shift @$_; join(';', map { uri_escape($k) . '=' . uri_escape($_) } @$_) } map { [$_, $CGI->param($_)] } $CGI->param() ); # now we can send a GET rquest somewhere $CGI->redirect('http://my.server.com/script.pl?' . $query);