The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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
|
|