我在解析文本文件的输出时遇到问题。我想在字符之间添加管道符号进行类似于 egrep 的多重搜索,文本文件如下
service entered the stopped state,critical
service entered the running state,clear
代码:
open(my $data, '<', $Config_File) or die "Could not open '$Config_File"
my $reg_exp;
my $severity;
my @fields=();
while (my $line = <$data>)
{
chomp $line;
if(!$line =~ /^$/)
{
@fields = split "," , $line;
$reg_exp = $fields[0];
$severity = $fields[1];
print $reg_exp;
}
}
#print $fields[0];
#last unless defined $line;
close($data);
预期产出
service entered the stopped state|service entered the running state