P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
All of these variables are related in some way. I don't know how they're related, but obviously they must be, or you wouldn't be testing them all at once as you are. It seems that their relationship is, at least, that failure to be set somehow will generate a call to help(). Since they're all related, it makes more sense (to me) to group them together in a single container. And since they seem to each have descriptive names, the container would be a hash. You also mentioned somewhere in this thread that you might not be testing each one against an empty string. I assume that means you might want to test them all against either a predetermined value, or a pattern match, or a range of permissible values. This would be fun to code in a more elegant way, but I would at least want to know what sorts of tests would be required for each value; tests against a single value, an enumerated list of possibilities, a pattern match, etc. But my thought is that you would also have a hash that associates these keys with the values they're allowed to have. Then you can do a Boolean test by iterating over the elements of the inputs and comparing them against the same elements of the validating hash. Sometimes simply associating coderefs with the validating hash's keys is helpful; each coderef would return true or false if the value passed in as a parameter validates against what you want to permit. Dave In reply to Re: checking values of variables
by davido
|
|