Greetings Monks;
The title isn't terribly descriptive, and I couldn't think of anything better in such a short space... At any rate, this issue:

I'm working on a set of CGIs which read in a number of vars from a FORM submit. I have a list of vars which cannot be empty, so after I read in all the var's using ->param(), I have something like this:

if ($var eq "" || $var2 eq "" || $var3 eq ""} { &complain(); }
Now I've been told that this list of non-empty fields can change depending on the whim of the customer. Therefore I need to have a better, less hard-coded, way of checking the vars. The list of vars that must be non-empty will be imported from DBI, since everything is database based anyway.
My problem is trying to work out a tidy way of actually taking this list of fields and comparing it to the bunch of scalars I have. I could make a hash, and have some kind of routine to check over the hash, ala:
my $var1 = $cgi->param('var1'); my $var2 = $cgi->param('var2'); my $var3 = $cgi->param('var3'); my $h = { 'var1' => $var1, 'var2' => $var2, 'var3' => $var3 }; my @list = qw(var1 var3); foreach (@list) { if (!exists $$h{$_}) { &complain; } }
But that is somewhat untidy, as you can see.
How would you do the above?

My thanks,
JP,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --


In reply to Validating the contents of scalars using an array based list by JPaul

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.