any pitfalls or better ways of doing this?

Yes, two of them. First, this code won't run under strict, and second, it allows malformed input to set any global variable it wants, which could do unforseen things with your script. You can solve both of these problems in either of two ways. The first is to use a single hash, instead of many globals. This is what I do:

foreach my $field ( @params ) { $input{$field} = param( $field ); }

This requires the rest of your script to use the hash values (like $input{foo} instead of just $foo), but it's straightforward and works. The other way is to expressly list what variables the user is permitted to set, and ignore any others. In order to get it to run under strict, you also have to add a line to allow the symbolic references:

foreach my $field qw(foo bar baz quux wibble) { no strict refs; $$field = param( $field ); }

This still requires you to list all the variables, but you don't have to have a separate assignment line for each, and you don't have to change the rest of the script to use a hash.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

In reply to Re: More efficient reading of forms in CGI by jonadab
in thread More efficient reading of forms in CGI by bradcathey

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.