Perl/CGI question

JD Austin plug-discuss@lists.plug.phoenix.az.us
Thu, 16 May 2002 15:19:38 -0700 (MST)


Heres a script that demonstrates what I think you want.


JD

#!/usr/bin/perl
         use CGI qw/:standard/; #CGI is installed by default usually.
         $query=new CGI;  # create a new cgi object
          print $query->header; # print the content header
          %namepair=undef; # this is a perl hash.. will use $namepair below.
          #an html form to show it works
          print '
<html>
<form method=post action=\'/cgi-bin/test.cgi\'>
1<input type=text name=foo1><BR>
2<input type=text name=foo2><BR>
3<input type=text name=foo3><BR>
4<input type=text name=foo4><BR>
<input type=submit name=submit value=\'submit button\'>
</form>';
          if ($query->param()) { #param what CGI holds the POST/Get data in
              @names = $query->param; #load the names into an array
              for ($i=0;$i<@names;$i++){
               #load the names/values into an associative array
                print $names[$i]."<BR>";
               $namepair{$names[$i]}=$query->param($names[$i]);
              }
              #show it actually worked:
              for ($i=0;$i<@names;$i++){
                print $names[$i].'='.$namepair{$names[$i]}."<BR>";
              }
          }




> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have a form that uses POST to pass two name/value pairs to a perl
> script.   What is the best way to get those name/value pairs into a
> perl array? - --
> Jim
>
> Freedom is worth protecting
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGP 6.5.8
>
> iQA/AwUBPOQXXSsk3ywszI1FEQI0SgCgt+4CjJaKGA1MSsQv/xO4pFWAEp8AoMp8
> STvZPkqnOPBI/xmPOA/i/8+z
> =flfF
> -----END PGP SIGNATURE-----
> ________________________________________________
> See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't
> post to the list quickly and you use Netscape to write mail.
>
> PLUG-discuss mailing list  -  PLUG-discuss@lists.plug.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss