| 1 | package Set::Formula; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.8.8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | require Exporter; | |||||||||||||||||||||||||||
| 8 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 9 | 3 | our @EXPORT = qw(formula_checker formula_calcul equality_checker); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Carp qw(cluck); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 13 | 3 | my $debug = 0; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | my %operators = ( | |||||||||||||||||||||||||||
| 16 | '+' => \&_union | ||||||||||||||||||||||||||||
| 17 | ,'-' => \&_complement | ||||||||||||||||||||||||||||
| 18 | ,'^' => \&_intersection | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | my $counter = 0; | |||||||||||||||||||||||||||
| 22 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 23 | sub _union | ||||||||||||||||||||||||||||
| 24 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_union: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 25 | 2 | my ($hrefA, $hrefB, $href_result) = @_; | |||||||||||||||||||||||||||
| 26 | 2 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | for (keys %{$hrefA}) { ${$href_result}{$_} = 0 } | |||||||||||||||||||||||||||
| 29 | 2 | for (keys %{$hrefB}) { ${$href_result}{$_} = 0 } | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 32 | sub _complement | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | { # Result := A - B | ||||||||||||||||||||||||||
|
Subroutine
_complement: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 34 | 2 | my ($hrefA, $hrefB, $href_result) = @_; | |||||||||||||||||||||||||||
| 35 | 2 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | for (keys %{$hrefA}) | |||||||||||||||||||||||||||
| 38 | 4 | ▶ | { unless (exists ${$hrefB}{$_}) { ${$href_result}{$_} = 0 } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 41 | sub _intersection | ||||||||||||||||||||||||||||
| 42 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_intersection: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 43 | 4 | my ($hrefA, $hrefB, $href_result) = @_; | |||||||||||||||||||||||||||
| 44 | 4 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 4 | for (keys %{$hrefB}) | |||||||||||||||||||||||||||
| 47 | 18 | ▶ | { if (exists ${$hrefA}{$_}) { ${$href_result}{$_} = 0; } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 50 | sub equality_checker # returns 1 if equal, else 0 | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
equality_checker: called CC=9 SCAR=28.1
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 2 | my ($hrefA, $hrefB, $debug) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $debug = (defined $debug)? 1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | if ($debug) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 0 | printf "*** %s: running in debug mode ***\n", (caller(0))[3]; | |||||||||||||||||||||||||||
| 58 | 0 | print "DEBUG: 1st operand: "; for (sort keys %{$hrefA}) { print "$_ "; }; print "\n"; | |||||||||||||||||||||||||||
| 59 | 0 | print "DEBUG: 2nd operand: "; for (sort keys %{$hrefB}) { print "$_ "; }; print "\n"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | for (keys %{$hrefA}) | |||||||||||||||||||||||||||
| 63 | 5 | ▶ | { unless (exists ${$hrefB}{$_}) { return 0 } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | for (keys %{$hrefB}) | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | { unless (exists ${$hrefA}{$_}) { return 0 } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 1 | return 1; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub formula_checker # returns true on success and undefined value on error | ||||||||||||||||||||||||||||
| 72 | 14 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
formula_checker: called CC=34 SCAR=37.1
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 14 | my $formula = shift; | |||||||||||||||||||||||||||
| 74 | 14 | my $remainder; | |||||||||||||||||||||||||||
| 75 | 14 | ▶ | my $debug = (defined $ARGV[0]) && $ARGV[0] ?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ARGV[0] and $ARGV[0]
MC/DC0%0/2
defined $ARGV[0] and $ARGV[0]
defined $ARGV[0]
$ARGV[0]
Truth table33%1/3
A and B
A= defined $ARGV[0]B= $ARGV[0]
| |||||||||||||||||||||||||||||
| 76 | 14 | ▶ | $debug && printf "*** %s: running in debug mode ***\n", (caller(0))[3]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 14 | ▶ | unless (defined $remainder) { $remainder = ''; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 14 | my $parentheses_cnt = 0; | |||||||||||||||||||||||||||
| 79 | 14 | my $parentheses_number_cnt = 0; | |||||||||||||||||||||||||||
| 80 | 14 | my $operator; | |||||||||||||||||||||||||||
| 81 | my $regexpr ; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # ---- check "interlacing": start ---- | ||||||||||||||||||||||||||||
| 84 | # rule 1: 2 operands can't be adjacent | ||||||||||||||||||||||||||||
| 85 | # rule 2: 2 operators can't be adjacent | ||||||||||||||||||||||||||||
| 86 | # rule 3: operator can be neither first not last formula element | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 14 | ▶ | $debug && print "DEBUG 10: formula: $formula\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 14 | $remainder = $formula; | |||||||||||||||||||||||||||
| 90 | 14 | $remainder =~ s/[()]//g; # remove all parentheses | |||||||||||||||||||||||||||
| 91 | 14 | ▶ | $debug && print "DEBUG 20: remainder: $remainder\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 14 | my $operator_found = 0; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | INTERLACING: | ||||||||||||||||||||||||||||
| 95 | 14 | while(1) | |||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 34 | ▶ | unless ( $remainder =~ /^\s*(\w+)\s*/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 2 | ▶ | $debug && cluck "ERROR: remainder of formula $remainder must begin with operand"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 2 | return; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 32 | $remainder = $'; | |||||||||||||||||||||||||||
| 104 | 32 | ▶ | $debug && print "DEBUG 30: operand: $1 remainder: $remainder\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 32 | ▶ | unless ($remainder) { last INTERLACING; } # interlacing is correct | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 23 | $operator_found = 0; | |||||||||||||||||||||||||||
| 109 | 23 | for (keys %operators) | |||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 40 | ▶ | $debug && print "DEBUG 40: operator: $_\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 40 | $regexpr = qq (^\\s*(\\$_)\\s*); | |||||||||||||||||||||||||||
| 113 | 40 | ▶ | $debug && printf "DEBUG 45: regexpr = %s\n", $regexpr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 40 | ▶ | if ( $remainder =~ /$regexpr/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | { | ||||||||||||||||||||||||||||
| 116 | 22 | $operator_found = 1; | |||||||||||||||||||||||||||
| 117 | 22 | $operator = $_; | |||||||||||||||||||||||||||
| 118 | 22 | $remainder = $'; | |||||||||||||||||||||||||||
| 119 | 22 | last; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 23 | ▶ | unless ($operator_found) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||
| 125 | 1 | ▶ | $debug && cluck "ERROR: remainder of formula $remainder must begin with operator"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | return; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 22 | ▶ | $debug && printf "DEBUG 50: operator: %s\n", $operator; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 22 | ▶ | unless ($remainder) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 2 | ▶ | $debug && cluck "ERROR: formula must begin with operator"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 2 | return; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } # end of 'while (1)' | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # ---- check "interlacing": finish ---- | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # ---- check parentheses: start ---- | ||||||||||||||||||||||||||||
| 141 | 9 | $remainder = $formula; | |||||||||||||||||||||||||||
| 142 | 9 | ▶ | $debug && printf "DEBUG 60: *** remainder = %s\n", $remainder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 9 | for $operator (keys %operators) | |||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | 23 | $regexpr = qq (\\(\\s*\\$operator|\\$operator\\s*\\)); | |||||||||||||||||||||||||||
| 147 | 23 | ▶ | $debug && printf "DEBUG 65: *** operator = %-3s regexpr = %s\n", $operator, $regexpr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 23 | ▶ | if ( $remainder =~ /$regexpr/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 2 | ▶ | $debug && cluck "ERROR: $& has no sense"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 2 | return; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 7 | ▶ | while ($remainder =~ /[()]/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | 26 | ▶ | $debug && printf "DEBUG 70: *** remainder = %s\n", $remainder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 26 | $parentheses_number_cnt ++; | |||||||||||||||||||||||||||
| 159 | 26 | $remainder = $'; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | unless (defined $remainder) { $remainder = ''; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 26 | ▶ | $debug && printf "DEBUG 75: *** remainder = %s\n", $remainder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 26 | ▶ | if ( $& =~ /\(/ ) { $parentheses_cnt ++; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | else | ||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 13 | $parentheses_cnt --; | |||||||||||||||||||||||||||
| 166 | 13 | ▶ | if ($parentheses_cnt < 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||
| 168 | 2 | ▶ | $debug && cluck "ERROR: negative parentheses amount at parentheses nr.$parentheses_number_cnt from left"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 2 | return; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } # end of "while ($remainder)" | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 5 | ▶ | if ($parentheses_cnt) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||
| 176 | 2 | ▶ | $debug && cluck "ERROR: more opening parentheses than closing parentheses"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 2 | return; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 3 | return 1; | |||||||||||||||||||||||||||
| 180 | } # end of "sub formula_checker" | ||||||||||||||||||||||||||||
| 181 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 182 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | sub formula_calcul | ||||||||||||||||||||||||||||
| 185 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
formula_calcul: called CC=32 SCAR=44.5
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 12 | my ($curr_formula, $href_result, $href_HoH_sets, $debug) = @_; | |||||||||||||||||||||||||||
| 187 | 12 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | unless (defined $curr_formula) { $curr_formula = '' } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 12 | ▶ | $debug = (defined $debug) && $debug ?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $debug and $debug
MC/DC0%0/2
defined $debug and $debug
defined $debug
$debug
Truth table66%2/3
A and B
A= defined $debugB= $debug
| |||||||||||||||||||||||||||||
| 191 | 12 | ▶ | $debug && printf "*** %s: running in debug mode ***\n", (caller(0))[3]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 12 | ▶ | $debug && print "\n--------------------------\n#1 curr_formula = $curr_formula\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 12 | my $href_operand_left; | |||||||||||||||||||||||||||
| 196 | my $href_operand_right; | ||||||||||||||||||||||||||||
| 197 | 12 | my $operator; # a key of %operators | |||||||||||||||||||||||||||
| 198 | 12 | my $href_remainder; | |||||||||||||||||||||||||||
| 199 | 12 | my $new_name; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # parse formula: search internal (...) | ||||||||||||||||||||||||||||
| 202 | 12 | ▶ | while ( $curr_formula =~ /\(([^(]+?)\)/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||
| 204 | # $curr_formula contains parentheses | ||||||||||||||||||||||||||||
| 205 | # $1 is innenmost formula part, that does not contains parentheses. | ||||||||||||||||||||||||||||
| 206 | # Opened and closed parentheses are located on boundaries of $1 and don't belong it. | ||||||||||||||||||||||||||||
| 207 | 6 | ▶ | $debug && print "#2 in parentheses: $1\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | #------------------------------------------# | ||||||||||||||||||||||||||||
| 209 | 6 | ▶ | unless (defined &formula_calcul ($1, $href_result, $href_HoH_sets, $debug)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 2 | ▶ | { $debug && cluck "Error in formula \"$1\""; return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 4 | $new_name = "InTeRmEdIaTe$counter"; | |||||||||||||||||||||||||||
| 213 | 4 | $counter++; | |||||||||||||||||||||||||||
| 214 | 4 | for (keys %{$href_result}) { $href_HoH_sets->{$new_name}{$_} = 0; } | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | unless (exists $href_HoH_sets->{$new_name}) { $href_HoH_sets->{$new_name} = () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 4 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 4 | $curr_formula = "$` $new_name $'"; | |||||||||||||||||||||||||||
| 219 | 4 | ▶ | $debug && print "#3 curr_formula = $curr_formula\n\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | # parenthesesless formula. | ||||||||||||||||||||||||||||
| 223 | # Calculate all operators with equal priority from left to right | ||||||||||||||||||||||||||||
| 224 | 10 | ▶ | if ( $curr_formula =~ /(\w+)\s*(\S+)\s*(\w+)/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||
| 226 | 10 | $href_operand_left = $1; | |||||||||||||||||||||||||||
| 227 | 10 | $operator = $2; | |||||||||||||||||||||||||||
| 228 | 10 | $href_operand_right = $3; | |||||||||||||||||||||||||||
| 229 | 10 | $href_remainder = $'; | |||||||||||||||||||||||||||
| 230 | 10 | ▶ | if ($operator !~ /^(\+|\-|\^)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | { $debug && cluck "ERROR: Unknown operator \"$operator\" in formula \"$curr_formula\"\n"; return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 10 | ▶ | $debug && printf "*** left operand = $href_operand_left, operator = $operator, right operand = $href_operand_right, remainder = %s\n", $href_remainder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 10 | ▶ | unless (exists $href_HoH_sets->{$href_operand_left}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||
| 237 | 2 | ▶ | $debug && cluck "ERROR: Unknown left operand \"$href_operand_left\" in formula \"$curr_formula\"\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 2 | return; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 8 | ▶ | unless (exists $href_HoH_sets->{$href_operand_right}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $debug && cluck "ERROR: Unknown right operand \"$href_operand_right\" in formula \"$curr_formula\"\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | return; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 8 | ▶ | if ($debug) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||
| 249 | 0 | printf "!!! %-13s : ", $href_operand_left; | |||||||||||||||||||||||||||
| 250 | 0 | for ( keys %{$href_HoH_sets->{$href_operand_left}} ) {print "$_ "} | |||||||||||||||||||||||||||
| 251 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | printf "!!! %-13s : ", $href_operand_right; | |||||||||||||||||||||||||||
| 254 | 0 | for ( keys %{$href_HoH_sets->{$href_operand_right}} ) {print "$_ "} | |||||||||||||||||||||||||||
| 255 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | $operators{$operator} ( $href_HoH_sets->{$href_operand_left} | ||||||||||||||||||||||||||||
| 259 | 8 | , $href_HoH_sets->{$href_operand_right} | |||||||||||||||||||||||||||
| 260 | , $href_result ); | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 8 | ▶ | if ($debug) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||
| 264 | 0 | print "DEBUG: result of ($href_operand_left $operator $href_operand_right) : "; | |||||||||||||||||||||||||||
| 265 | 0 | for (keys %{$href_result}) { print "$_ " } | |||||||||||||||||||||||||||
| 266 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 8 | ▶ | if ($href_remainder =~ /\S/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||
| 271 | 2 | $new_name = "InTeRmEdIaTe$counter"; | |||||||||||||||||||||||||||
| 272 | 2 | $counter++; | |||||||||||||||||||||||||||
| 273 | 2 | for (keys %{$href_result}) { $href_HoH_sets->{$new_name}{$_} = 0 } | |||||||||||||||||||||||||||
| 274 | 0 | ▶ | unless (exists $href_HoH_sets->{$new_name}) { $href_HoH_sets->{$new_name} = () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 2 | %{$href_result} = (); # reset this hash | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 2 | $curr_formula = "$new_name $href_remainder"; | |||||||||||||||||||||||||||
| 278 | 2 | ▶ | $debug && print "#4 curr_formula = $curr_formula\n\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 2 | ▶ | if (defined &formula_calcul ($curr_formula, $href_result, $href_HoH_sets, $debug)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 2 | { return 1; } | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | else { $debug && cluck "ERROR 33\n"; return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | } # end of "if ( $curr_formula =~ ...)" | ||||||||||||||||||||||||||||
| 284 | 6 | return 1; | |||||||||||||||||||||||||||
| 285 | } # end of "sub formula_calcul" | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 3 | 1; | |||||||||||||||||||||||||||
| 288 | __END__ | ||||||||||||||||||||||||||||