"obligatory"--how about calling it "required" instead? "min", "max,"--minimum and maximum what? How about "minlength" and "maxlength" instead? Another thing I'd recommend is, Instead of having a "regex" parameter you just have a catch-all "value" parameter that can contain a string, a number, or a compiled regex that you compare the actual parameter value with. To distinguish between them, remember that any string containing a regex compiled with the qr// operator has a ref type of "Regexp," e.g., this:
my $re = qr/some(thing)?/; print ref $re;
Prints out "Regexp". No, this behavior is NOT documented (at least that I can find), but it's quite useful. So you can do something like this:
my $matches; if (ref $value eq 'Regexp') { $matches++ if ($param_value =~ $value); } else { $matches++ if ($param_value eq $value); }
Which compares the parameter value in $param_value against the regex in $value if $value if it contains a compiled regex, or it just compares the string or number in $value against the parameter value in $param_value otherwise.
In reply to Re: Check user input - reimplementation
by William G. Davis
in thread Check user input - reimplementation
by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |