Condi: !RET&(!DFTRAMBYP&((TENA&! QNAPA&! CENA)|(!TENA&!TONAPA&!TCENA)) IDFTRAMBYP) &EMAA[2]&EMAA[1]&EMAA[O]&EMASA Sub_whenw: !RET&!DFTRAMBYP&TENA&!TONAPAS!CENA&EMAA[2]&EMAA[1]&EMAA[0]&EMASA !RET&!DFTRAMBYP&!TENA&!TONAPA&!TCENA&EMAA[2]&EMAA[1]&EMAA[0]&EMASA !RET&DFTRAMBYP&EMAA[2]&EMAA[1]&EMAA[0]&EMASA condi: !RET&TENA&((DFTRAMBYP&!SEA)I(!DFTRAMBYP&!CENA)) sub_whenw: !RET&TENA&DFTRAMBYP&!SEA !RET&TENA&!DFTRAMBYP&!CENA 根据上面的cond使用perl转化成下面的sub_whenw,给出通用的代码设,the condi can split to sub_whenw by '|' , this is kind of de-morgon law appliment
时间: 2023-12-18 14:02:36 浏览: 70
Based on the given `cond` and `sub_whenw`, to split the `cond` by '|' and convert it to `sub_whenw` using De Morgan's law, you can use the following Perl code:
```
# split the cond by '|'
my @conditions = split /\|/, $cond;
# convert each condition to sub_whenw using De Morgan's law
my @sub_whenw;
foreach my $condition (@conditions) {
$condition =~ s/(\w+)/!$1/g; # negate all variables
$condition =~ s/\(/\(/g; # add back the opening parentheses
$condition =~ s/\)/\)/g; # add back the closing parentheses
$condition =~ s/!/~/g; # replace '!' with '~' for bitwise negation
my $sub = eval($condition); # evaluate the condition as a bitwise expression
$sub =~ s/(\d+)/$1 ? 'T' : 'F'/eg; # convert the bitwise result to 'T' or 'F'
push @sub_whenw, $sub;
}
# print the resulting sub_whenw
print join("\n", @sub_whenw);
```
This code first splits the `cond` by '|' into an array of individual conditions. It then loops through each condition and applies De Morgan's law by negating all variables, replacing '!' with '~' for bitwise negation, and evaluating the condition as a bitwise expression using `eval()`. Finally, it converts the bitwise result to 'T' or 'F' and adds the resulting `sub_whenw` to an array. The code then prints the resulting `sub_whenw` array.
阅读全文