【发布时间】:2017-07-07 10:27:49
【问题描述】:
我想在日志文件中的特定单词 (Current Value = ) 之后搜索值,并创建一个带有值的字符串。
vcs_output.log:一个日志文件
** Fault injection **
Count = 1533
0: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rcc_data_e[6]
0: Current value = x
1: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rs3_data_e[51]
1: Current value = x
2: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rs1_data_e[3]
2: Current value = 1
3: Path = cmp_top.iop.sparc0.exu.alu.shft_alu_shift_out_e[18]
3: Current value = 0
4: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rs3_data_e[17]
4: Current value = x
5: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rs1_data_e[43]
5: Current value = 0
6: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rcc_data_e[38]
6: Current value = x
7: Path = cmp_top.iop.sparc0.exu.alu.byp_alu_rs2_data_e_l[30]
7: Current value = 1
.
.
.
如果我在“当前值 =”之后存储值,则为 x,x,1,0,x,0,x,1。我最终将它们保存/打印为字符串,例如 xx10x0x1。
这是我的代码 代码.pl:
#!/usr/bin/perl
use strict;
use warnings;
##### Read input
open ( my $input_fh, '<', 'vcs_output.log' ) or die $!;
chomp ( my @input = <$input_fh> );
my $i=0;
my @arr;
while (@input) {
if (/Current value = /)
$arr[i]= $input; # put the matched value to array
}
}
## make a string from the array using an additional loop
close ( $input_fh );
我认为有一种方法可以在一个循环中创建一个字符串(甚至不使用循环)。请建议我去做。任何建议表示赞赏。
【问题讨论】: