A little more explanation:
use strict; use warnings; use CGI;
Use strict and -w, except of course for one-liners and/or short throwaway scripts. Note that the warnings pragma only works under Perl v5.6.0+.
my $q = CGI->new; my @names = $q->param; my %param;
This instantiates the CGI object and fills @names with the parameter list, then declares %param, to be used later.
foreach my $name (@names)
Iterating over each parameter in order,
{ $param{$name} = $q->param($name);
Set the value in the parameter hash ($param{$name}) to the parameter value ($q->param($name))...
print "$name: $param{$name}", $q->br; }
... and print it; the $name and $param{$name} values are interpolated into the string. $q->br just generates an empty BR tag.

The other version:

use strict; use warnings; use CGI; my $q = CGI->new;
Same as before.
my %params = map { $_, $q->param($_) } ($q->param);
This simultaneously instantiates %params and fills it with, for each element in $q->param (the parameter list), the name ($_, the placeholder variable -- see map / perlvar) plus the value ($q->param($_)). When this is put into a hash these pairs turn into keys and values.
print join $q->br, map { "$_: $params{$_}" } ($q->param);
This first takes the parameter list ($q->param) and maps each element to the string "$_: $params{$_}" which is the name ($_) plus a colon, space, and value ($params{$_}) -- accessing an element of the params hash with key being the name. Then it joins these strings together with the empty BR tag, and prints the result. Hope this helps.

In reply to Re: Re: Re: Web form security by premchai21
in thread Web form security by earthboundmisfit

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.