JPaul has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.if ($var eq "" || $var2 eq "" || $var3 eq ""} { &complain(); }
But that is somewhat untidy, as you can see.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; } }
My thanks,
JP,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --
|
|---|