There's always the TMTOWTDI principle, but allow me to point out a potential problem here:

Your checks are now position dependent. If you move a block of code around in the section that builds the byte string, causing the byte position to change, you'll be spending the next few days debugging.

A more managable way to do this is with a bit field. By having each check toggle a bit on or off, you can now compare against a full value:
# # $word is 0, the default setting for bits being 0FF # $word = 0; $word |= 0x01 if ($obj->{organization} !~ /^\s*$/); ... $word |= 0x40 if ($obj->{report} !~ /^\s*$/); print "All fields supplied" if ($word == 0x00); print "Missing Organization" if ($word & 0x01 == 0);
Now, as long as you don't duplicate bit positions, you run into far less chances of fubar'ing the code should you insert tests, etc.

But this really isn't the best way either, since the code that sets the bit position and the code that tests for it are separated, and use magic numbers. You should use constants, to make sure you mean the same thing in both places.

There are a couple of good books that talk about how to prevent problems like this from creeping up on you. There is 'The Pragmatic Programmer', 'Code Complete', another good one whose name escapes me at the moment (it's on my bookshelf at home, and I'm not awake).

--Chris

e-mail jcwren

In reply to (jcwren) RE: Building a byte to test truth table by jcwren
in thread Building a byte to test truth table by PsychoSpunk

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.