note
zakb
<p>Your validation tests look reasonable. One optimisation would be to use an array for the error messages, like so:</p>
<code># untested, change to suit
my @messages;
if ( ....test.... )
{
push @messages, "The error message";
}
# more tests
PrintError if @messages;
sub PrintError
{
# any initial html stuff, or use a template
print join('<br>', @messages);
}
</code>
<p>...which means you don't need to maintain a flag.</p>
<p>Looking on CPAN, I see [cpan://CGI::Validate] which appears to a a Getopt style validator and [cpan://Params::Validate] which may be useful.</p>
<p><strong>Update:</strong>[Podmaster] suggested [cpan://Data::FormValidator], which is what I was trying to find.</p>
<p><strong>Update2:</strong> I left the & in there because that's what the supplicant had - now removed. For reasons why not to do this, see [perlsub]. Basically, with the &, the argument list to a sub is optional and you will get the @_ array visible <em>at the time of calling</em> in the subroutine.</p>
254971
254971