in reply to Shorten function conditions
Naturally, this being Perl, we can use idiomatic techniques with hashes and regexes rather than a by-the-book C-ish implementation.
An (untested) stab at your problem might look like this:
# Keys in %rules are ! $macf, ! $syman, eq $oldMac, eq $oldSym my %rules = ( '1111' => 'no changes', '1100' => 'section C UPDATE', '1101' => 'section B UPDATE', '1110' => 'SEction E updated', '100.' => 'MacSEction updated', '101.' => 'no changes to mac', '01.0' => 'syman update', '01.1' => 'no changes to syman', ); sub mainfunction { my $state = join('', map { $_ ? 1 : 0 } ($macf == 0), ($syman == 0), ($mac eq $oldMac), ($sym eq $oldSym) ); if ( my $rule = ( grep { $state =~ $_ } keys %rules )[0] ) { my $result = $rules->{$rule}; print $result . "\n"; } }
|
|---|