in reply to submitting a form from within a script

here's a trivial demo that outlines the basics. as the monks have already noted, LWP::Simple is a good solution for GET's. the 'map' statement just forms the foo=somevalue pairs. the get() is an LWP::Simple method that makes the HTTP request and returns the page returned by the remote (or in this case, local) server.

#!/usr/bin/perl -Tw
use CGI qw( :header :param );
use LWP::Simple;
use strict;

my %pairs = ();
my $remote_script = "http://localhost/cgi-bin/demo.pl"; 

for my $p ( qw( foo bar  ) ) { # assume 'foo' and 'bar' are the params
$pairs{$p} = param($p);
}

# there's more than one way to do this . . .
my @params = map { $_ = $_ . '=' . $pairs{$_} } keys %pairs;
my $url = $remote_script . '?' . join '&', @params;

print header;
print "GET'ing $url<p>\n";
print get($url);

  • Comment on Re: submitting a form from within a script