我在(How can I print all the lines between the previous and next empty lines when a match is found?)讀過類似的問題!並嘗試在空行之間打印所有行,但不打印。這是我嘗試過的腳本,請正確處理它以符合我的要求。Perl腳本在空行之間打印行
my @file = <IN>;
for (0 .. $#file) {
if ($file[$_] =~ /Match/){
my $start = $_;
while ($start >= 0 && $file[$start] !~ /^$/) {
$start--; # $start points to first empty line
}
my $end = $_;
while ($end <= $#file && $file[$end] !~ /^$/) {
$end++; # $end points to next empty line
}
print OUT "\[email protected][$start+1..$end-1]"; #it should print between two empty lines right??
}
}
輸入文件:要求
wire enable,GSMC_G8,mkf_g,un1_G11_0, GND_net_1, VCC, G8, G16, Q_RNIUQAA, CK_c, reset_c,
G0_c, G1_c, G17_c, G2_c, G3_c, G17_c_i, GND_1, VCC_0;
INBUF G3_pad (.PAD(G3), .Y(G3_c));
dff_0_1 DFF_1 (.G17_c(G17_c), .reset_c(reset_c), .CK_c(CK_c),
.G0_c(G0_c), .G8(G8));
GND GND_i_0 (.Y(GND_1));
NOR2 G3_pad_RNIUUQF (.A(G8), .B(G3_c), .Y(G16));
INV G17_pad_RNO (.A(G17_c), .Y(G17_c_i));
VCC VCC_i (.Y(VCC));
CLKBUF CK_pad (.PAD(CK), .Y(CK_c));
endmodule
輸出文件:
INBUF G3_pad (.PAD(G3), .Y(G3_c));
dff_0_1 DFF_1 (.G17_c(G17_c), .reset_c(reset_c), .CK_c(CK_c),
.G0_c(G0_c), .G8(G8));
GND GND_i_0 (.Y(GND_1));
NOR2 G3_pad_RNIUUQF (.A(G8), .B(G3_c), .Y(G16));
INV G17_pad_RNO (.A(G17_c), .Y(G17_c_i));
VCC VCC_i (.Y(VCC));
CLKBUF CK_pad (.PAD(CK), .Y(CK_c));
請包括一個示例輸入文件和所需的輸出。你可以[編輯]你的問題。 – simbabque
另外,請'使用嚴格'和'使用警告'。代碼中有幾個語法問題。數學運算符不能用字符串插值。你的'print'語句不會做你認爲它的作用。 – simbabque
解析Verilog:https://metacpan.org/pod/Verilog-Perl – toolic