【发布时间】:2021-12-08 23:36:32
【问题描述】:
我有两个输入文件:filea 和 fileb。在filea 中,我有一个字符串$pc_count$,而在fileb 中,有数字和字符串。我必须在fileb 中搜索数字并在filea 中替换$pc_count$。
我试过下面的代码,但是fileb的第一个值每次都重复($pc_count$)。
open (IN_FILE, "<filea") or die "Please provide an correct file path\n";
open (IN_FILE1, "<fileb") or die "Please provide an correct file path\n";
my $i = 0;
while (<IN_FILE>) {
if($_ =~ /\$pc_count\$/) {
my $line = $_;
while (<IN_FILE1>) {
if($_ =~ /([a-z0-9-]+)[\s]+/) {
my $first = $1;
$line =~ s/\$pc_count\$/$first/;
#print OUT_FILE("$line");
print $line;
}
}
}
#print OUT_FILE("$_");
}
close IN_FILE;
close IN_FILE1;
文件
case(pc)
'h$pc_count$ : $display("checkdata string %s ",pc_string);
endcase
文件b
fe0000
fe0001
fe0002
fe0003
..
..
..
结果:
case(pc)
'hfe000 : $display("checkdata string %s ",pc_string);
'hfe000 : $display("checkdata string %s ",pc_string);
'hfe000 : $display("checkdata string %s ",pc_string);
'hfe000 : $display("checkdata string %s ",pc_string);
..
..
..
..
endcase
【问题讨论】: