user2506730
user2506730

Reputation: 21

Process URL in CGI script

read(STDIN, $FormData, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $FormData);                              
foreach $pair (@pairs) {

(name, $value) = split(/=/, $pair);          
$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;
    my $Var1 = $Form{Var1};
    my $Var2 = $Form{Var2};} 

I need help in Perl object oriented script modification, which processes the submitted data from URL, calls LDAP and get user parameters, adds these parameters to POST form and send http POST with all data to the same URL.

My goal is to modify the original Perl script to take multiple articles parameters. Multiple articles parameters will be in the form:

id0=7kqm0uoamdtkff548567abdi3a&qpw0=ATYP%2d.....
&id1=7kqm0uoamdtcccccckff54123abdfn5&qpw1=ATYP....
........
&idN=NXXXXXX&qpwN=ATYP%2d%201....

Where N <= 50

I've read the standard input (sent by the form)

I can't figure out how the new parameters:

idN    where N <= 50
qpwN   where N <= 50

can be added to the associative array %names

I've parsed the "^id" from the keys:

my $key;
my $count;
foreach $key (sort keys(%names)) {
if ($key =~ '^id') {
   print $key, '=', $names{$key}, "\n";
   $count++;
   }
}
print "Total articles number = $count\n";

if ($count <= 50) {
print "You ordered $count articles\n";
}
else {

print "You exceeded the 50 articles limit"
}

So I want to add two new parameters $idN & $qpwN where N <= 50 in this kind of form:

my $Var1 = $Form{Var1};
my $Var2 = $Form{Var2};

How can it be performed? Thank you in advance!

Esther

Upvotes: 2

Views: 272

Answers (1)

initself
initself

Reputation: 31

If you are processing data from a form in a Perl script, use CGI.pm and CGI::Expand to handle advanced query parameters.

#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Expand;

my $q = CGI->new;
my $p = CGI::Expand->expand_cgi($q);

$p will then contain all of your query parameters.

Upvotes: 3

Related Questions