I asked a few days ago about basic regex, I have realized that what I could do is since I have to perform similar regex on about 40+ input variables if I could make the regex string a variable and store it in a hash I sould make my system much more efficent.
#my idea
%character_tests{ "var1" , "^0-9",
"var2" , "^A-Za-z0-9\." );
#object update nethod
# ARGS: variable name , variable value
# RETURNS: 1 if sucessful, undef if not
# sets error vars not described here
sub update( $ )
{
if( $_[0] =~ /$character_tests{ $_[0] )/ )
{
&set_error_type = "illegal characters";
}
else
{
$self->{var1} = $_[0];
}
}
Is this good programming stype or am I shooting my self in the foot for later?