If you have a small number of different conditions, you may wish to use a dispatch table.
use strict;
use warnings;
my %condition = (
'(A&B)|(C&D)' => sub {
my ($aa, $bb, $cc, $dd) = @_;
return ($aa && $bb ) || ($cc && $dd );
},
'A|(B&C&D)' => sub {
my ($aa, $bb, $cc, $dd) = @_;
return $aa || ($bb && $cc && $dd );
}
);
my @flags = qw( 0 1 1 1 );
my @conditions_to_check = (
'A|(B&C&D)',
'FOO',
'(A&B)|(C&D)'
);
for my $cond_name ( @conditions_to_check ) {
if( exists $condition{$cond_name} ) {
if ( $condition{$cond_name} ->(@flags) ) {
print "Condition '$cond_name' is true\n"
}
else {
print "Condition '$cond_name' is false\n"
}
}
else {
print "Condition '$cond_name' is not defined\n";
}
}
__DATA__
Condition 'A|(B&C&D)' is true
Condition 'FOO' is not defined
Condition '(A&B)|(C&D)' is true
|