use strict; no strict 'refs'; #### # This is a hash of variable names with an anonymous array # of function references. Basically the variable is validated # using each of these functions, luckily for me there are no # composite validations ;-) my %affiliates = ( username=>[\&Username_check,\&Username_unique], surname=>[\&Usersurnamecheck], forename=>[\&Userfornametype], password=>[\&Userpassword_check], secretQuestion=>[\&Userpasswdanscheck], title=>[\&Usergender_type], mobileNumber=>[\&Mobile_validate], model=>[\&Ua_model_version_mandatory], homePhoneNumber=>[\&Telno_type], dateOfBirth=>[\&Userdatebirth_type], postCode=>[\&Userzipcode_type], alternativeEmail=>[\&Userextmail_type], address1=>[\&UserAddress_type] ); # Validate takes a hash as it's argument, the hash is # made of keys that are the variable names and values # that are the variable values. It only validates # the variables passed to it. By setting flags the # Severity of it's error handling can be controlled. sub validate { %params = @_; @bad=(); print join("\n",map{"$_=$params{$_}"}(keys %params),"\n") if $debug; foreach $param (keys(%params)) { if(exists($affiliates{$param})) { foreach $func (@{$affiliates{$param}}) { unless(&{$func}($params{$param})) { push @bad, "$param=$params{$param} "; return 0 if 1==$trap; } } } else { print "Warning: $param does not exist!\n" if 1==$warn; die "Fatal: unknown parameter $param.\n" if 1==$fatal; } } return !scalar(@bad); }