2
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

5
  • 3
    The CGI Perl module (which is in the Perl core, at least for the time being) has already implemented most of what you're doing here, and better. Learn to use it. Commented Jun 21, 2013 at 17:22
  • I've used the following modules in my script: Commented Jun 21, 2013 at 17:37
  • #!/usr/bin/perl use strict; use CGI; use Net::LDAP; use Encode qw(decode); use Digest::MD5 qw(md5_hex); Commented Jun 21, 2013 at 17:37
  • 1
    I don't see you actually using it in your script, though! You're still trying to read and parse POST parameters manually, which is crazy. Create a CGI object and use $q->param. Commented Jun 21, 2013 at 18:13
  • Thank you! I'll be playing with $q->param Commented Jun 23, 2013 at 21:10

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! I didn't use the CGI::Expand module. I'll read the documentation.
Again thank you very much! I's exactly what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.