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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.