leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:
My CGI script gets data from html forms. Forms that deliver data are encoded in many different ways:
I need to read all parameters from <input type="text" .... Current solution is:
#!/usr/bin/perl use CGI; my $q = CGI->new; my %params = map { $_ => $q->param($_) } $q->param(); ...
If CGI.pm is deprecated, then what is better solution that is as simple as CGI.pm? I don't want to put much boilerplate, or make huge application -- just read parameters in the most simple way.
Here is a CGI script for testing: lustra.pl/cgitest.pl, and this is source code of that script:
#!/usr/bin/perl use CGI; use JSON; my $q = CGI->new; my %headers = map { $_ => $q->http($_) } $q->http(); my %params = map { $_ => $q->param($_) } $q->param(); my %environ = map { ($_, $ENV{$_}) } grep { ! /ROOT|PATH|REMOTE|FILENAME|SERVER|SSL/ } keys %ENV; print <<HTML; Content-Type: text/html; charset=utf-8 <!DOCTYPE HTML> <html> <body> <pre> @{[ JSON->new->pretty->canonical->encode({ headers => \%headers, params => \%params, environ => \%environ, }) ]} </pre> <form method="get"> <input type="submit"> <input name="about" value="method get"> <input name="myname" value="Alfa"> <input name="myage" value="32"> <input name="unicode-test" value="ĄĆĘŁŃÓ& +#346;ŹŹŻ-ąćęłńóśź&# +380;-πœ©ß←↓→əŋæð„”µ≤≥»«§ +½€¢³²≠"> </form> <form method="post"> <input type="submit"> <input name="about" value="method post"> <input name="myname" value="Beta"> <input name="myage" value="44"> <input name="unicode-test" value="ĄĆĘŁŃÓ& +#346;ŹŹŻ-ąćęłńóśź&# +380;-πœ©ß←↓→əŋæð„”µ≤≥»«§ +½€¢³²≠"> </form> <form method="post" enctype="application/x-www-form-urlencoded"> <input type="submit"> <input name="about" value="method post, x-www-form-urlencoded"> <input name="myname" value="Gamma"> <input name="myage" value="12"> <input name="unicode-test" value="ĄĆĘŁŃÓ& +#346;ŹŹŻ-ąćęłńóśź&# +380;-πœ©ß←↓→əŋæð„”µ≤≥»«§ +½€¢³²≠"> </form> <form method="post" enctype="multipart/form-data"> <input type="submit"> <input name="about" value="method post, multipart/form-data"> <input name="myname" value="Teta"> <input name="myage" value="66"> <input name="unicode-test" value="ĄĆĘŁŃÓ& +#346;ŹŹŻ-ąćęłńóśź&# +380;-πœ©ß←↓→əŋæð„”µ≤≥»«§ +½€¢³²≠"> </form> <form method="post" enctype="text-plain"> <input type="submit"> <input name="about" value="method post, text-plain"> <input name="myname" value="Omega"> <input name="myage" value="45"> <input name="unicode-test" value="ĄĆĘŁŃÓ& +#346;ŹŹŻ-ąćęłńóśź&# +380;-πœ©ß←↓→əŋæð„”µ≤≥»«§ +½€¢³²≠"> </form> </body> </html> HTML
|
|---|