read_data: read failure for 4 bytes to client 158.136.150.108. Error = Connection reset by peer
在上面一行中,我想使用s///
运算符删除“read_data:”之后的行中的所有文本。
答案 0 :(得分:3)
答案 1 :(得分:2)
我用
$str =~ s/^read_data\K:.*//;
快速(由于不使用捕获)和简单。如果有换行,它甚至会保留换行符。如果要删除任何尾随换行符,请改用以下内容:
$str =~ s/^read_data\K:.*//s;
答案 2 :(得分:0)
#!/usr/bin/env perl
use warnings; use strict;
while (my $line = <DATA>) {
my ($event) = ($line =~ /^(read_data):/);
next unless defined $event;
print "$event\n";
}
__DATA__
read_data: read failure for 4 bytes to client 158.136.150.108. Error = Connection reset by peer