Beefy Boxes and Bandwidth Generously Provided by pair Networks
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
in thread checking values of variables by fionbarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found