【发布时间】:2020-05-12 18:27:51
【问题描述】:
我第一次尝试使用 perl 来处理 xlsx。即使单元格包含 1'b1 或 1'b0,else 条件也会始终执行。请帮帮我。
#!/usr/bin/perl -w
use Spreadsheet::ParseXLSX;
use Spreadsheet::WriteExcel;
use Switch;
# Creates object (parser) of ParseXLSX
my $parser = Spreadsheet::ParseXLSX->new();
# call parse method thro parser object for parsing and parse it to excel variable
$excel = $parser->parse('PinMux_Spec.xlsx');
#$test_cond = "TEST.mbist_mode == 1'b0 && DIG_PINMUX.FC_pti_en == 1'b1";
$file_func = "pinmux_func.csv";
open (FH_F,">$file_func") || die "cannot open $file_func\n";
# looping thro all the sheets in .xlsx sheet
foreach $sheet (@{$excel -> {Worksheet}})
{
if(index ($sheet ->{Name},"FUNCTIONAL_MODE") !=-1 ) {
$sheetname = $sheet -> {Name};
# max row depth
$sheet -> {MaxRow} ||= $sheet -> {MinRow};
$i=0;
# Row iteration outer loop ex cell[0][0], cell[1][0]..
foreach $row ($sheet -> {MinRow} .. $sheet -> {MaxRow})
{
# max column depth
$sheet -> {MaxCol} ||= $sheet -> {MinCol};
$j=0;
# Column iteration inner loop ex. cell[0][0], cell[0][1]..
foreach $col ($sheet -> {MinCol} .. $sheet -> {MaxCol})
{
# read content of cells in each row and column
$cell = $sheet -> {Cells} [$row] [$col];
$column[$j] = $cell-> {Val};
$j++;
}
####### MAJOR CODE ########
$OEN_SIGNAL = $column[1];
print FH_F "$OEN_SIGNAL";
if($OEN_SIGNAL eq "1'b1") { print FH_F "A"; }
elsif($OEN_SIGNAL eq "1'b0") { print FH_F "B"; }
else { print FH_F "C"; }
}
}
}
实际输出
$OEN_SIGNAL 操作
1'b1-A
1'b0-B
sda_oen-C
【问题讨论】:
-
根据您的输入,这应该是
if($OEN_SIGNAL eq "1b'1") ==> if($OEN_SIGNAL eq "1'b1")并且还使用chomp($OEN_SIGNAL); $OEN_SIGNAL =~ s/^\s+|\s+$//g;只是为了删除与 $/ 的当前值相对应的任何尾随字符串以及 if 条件之前是否有任何前导和尾随空格 -
问题在于 1b'1 => 1'b1。真的很抱歉犯了一个愚蠢的错误。