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="&#260;&#262;&#280;&#321;&#323;Ó& +#346;&#377;&#377;&#379;-&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&# +380;-&#960;œ©ß&#8592;&#8595;&#8594;&#601;&#331;æð„”µ&#8804;&#8805;»«§ +½€¢³²&#8800;"> </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="&#260;&#262;&#280;&#321;&#323;Ó& +#346;&#377;&#377;&#379;-&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&# +380;-&#960;œ©ß&#8592;&#8595;&#8594;&#601;&#331;æð„”µ&#8804;&#8805;»«§ +½€¢³²&#8800;"> </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="&#260;&#262;&#280;&#321;&#323;Ó& +#346;&#377;&#377;&#379;-&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&# +380;-&#960;œ©ß&#8592;&#8595;&#8594;&#601;&#331;æð„”µ&#8804;&#8805;»«§ +½€¢³²&#8800;"> </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="&#260;&#262;&#280;&#321;&#323;Ó& +#346;&#377;&#377;&#379;-&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&# +380;-&#960;œ©ß&#8592;&#8595;&#8594;&#601;&#331;æð„”µ&#8804;&#8805;»«§ +½€¢³²&#8800;"> </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="&#260;&#262;&#280;&#321;&#323;Ó& +#346;&#377;&#377;&#379;-&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&# +380;-&#960;œ©ß&#8592;&#8595;&#8594;&#601;&#331;æð„”µ&#8804;&#8805;»«§ +½€¢³²&#8800;"> </form> </body> </html> HTML

In reply to CGI.pm not good practice, so what is good, modern, practice for reading CGI paramters? by leszekdubiel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.