Re: Posting a Hash?
Gisle Aas (gisle@activestate.com)
11 Apr 2001 12:57:22 -0700
Chris Martino <chris@console.org> writes:
> I'm currently running a script which takes input from a text file, splits
> it into 7 fields, then submits it to a form. Code below:
>
> while (<FILE>) {
> ($f1, $f2, $f3, $f4, $f5, $f6, $f7) = split("\t", $_, 9999);
> $request = new HTTP::Request('POST', "http://app1.int2.fatshoe.com:7001/rebates");
> $request->content_type('application/x-www-form-urlencoded');
> $request->content("r0_f0=$f1&r0_f1=$f2&r0_f2=$f3&r0_f3=$f4&r0_f4=$f5&r0_f5=$f6&r0_f6=$f7");
> $response = $ua->request( $request );
> }
>
> Now, this all works fine, but the form can handle several posts at once.
> Notice the r0_f0, r0_f1, r0_f2, etc. Now the form can handle an infinate
> ammount of rows. For example, if I have 300 rows to process, the 300th
> row can be r300_f0, r300_f1, etc.
>
> Currently everything is being submitted one at a time with just r0_f*.
> Is there any way I can submit all the data in one clean sweep with one
> form post?
Something like this then:
#!/usr/bin/perl -w
my $row = 0;
my @data;
while (<DATA>) {
chomp;
my $col = 0;
push(@data, map { "r$row\_f" . $col++ => $_ } split(/\t/, $_));
$row++;
}
use HTTP::Request::Common qw(POST);
my $req = POST "http://app1.int2.fatshoe.com:7001/rebates", \@data;
print $req->as_string;
__END__
a b c
d e
f