Since you're using a hash to hold the object, reusing the keys to map to bit positions might help. For example:
@fields = qw(organization report foo bar baz);
$bit = 1;
foreach $field ( @fields ) {
    $bitmask{$field} = $bit;
    $bit <<= 1;
}

This reduces the code that build $mask to

foreach $field ( @fields ) {
    $mask |= $bit{$field} if $obj{$field} !~ /^\s*$/;
}

The challenging part is converting the static regular expressions to something dynamic. Here's one (untested) thought:

sub testMask {
    my($bits, $on, $off) = @_;
    my($onmask, $testmask) = 0;

    foreach $field ( @$on ) {
        $onmask |= $bit{$field};
        $testmask |= $bit{$field};
    }
    foreach $ field ( @$off ) {
        $testmask |= $bit{$field};
    }
    return ($bits & $testmask) == $onmask;
}

This lets you rewrite the tests as:

moreDatabaseProcessing() unless testMask($mask, \qw(organization), \qw(foo bar));

The up side of this approach is that it's completely position independent. The downside is that it's not resilient against field name typos, though that can be mitigated with some extra tests.


In reply to RE: (jcwren) RE: Building a byte to test truth table by dws
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.