Re: Posting a Hash?
Chris Martino (chris@console.org)
Wed, 11 Apr 2001 17:57:57 -0400 (EDT)
BAH... I need to learn to try other things out before I fire off another
email. Anywho, after a bit of playing I was able to get it to work.
Thanks!
Chris
On Wed, 11 Apr 2001, Chris Martino wrote:
> Ok, I tried plugging it in with a test script, and I keep on getting
> errors about a missing bracket, allthough the bracket is there. Here's
> the script:
>
> #!/usr/bin/perl -w
> open(FILE, '/tmp/report2.txt');
> while (<FILE>) {
> 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
>
> }
> close(FILE);
>
>
>
> On 11 Apr 2001, Gisle Aas wrote:
>
> > 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
> >
>