
How to Avoid Becoming a “Code Grinder” • Chapter 2 73
my $sth = $dbh->prepare($statement);
# execute our query, terminate upon error
$sth->execute
or die $sth->errstr;
# clean up after ourselves with the next two statements
$sth->finish;
$dbh->disconnect;
print "It worked!"
}
}
sub validate_form
{
# get the form name from the args passed to the sub
my $which_form = shift;
# create a hash with key: page1 with a value of the required fields,
# stored as an anonymous array.
Just a note on this validation routine:We’d usually have multi-page
applications, so this method becomes right handy. It might seem overkill
for such a small program, but I hope you get the point. ...