例如,如何在模式匹配的行之后访问所有行?
BCDA ABCD AAAABBBBCCCCDDD AAAAAABBBBBBCCC AAAAAAAAAAAAAA
因此,基本上,在模式ABCD匹配之后,我想在it.Put之后处理所有行,在array.So中只做一次模式匹配。
发布于 2011-07-28 21:32:40
这是我能想到的最简单的例子,听起来你想要的是什么。它将匹配到数组中的行放在“后面的所有行”。
my @lines;
while ( <$in> ) {
next unless m/ABCD/;
# in an list context, this will slurp the rest of the file.
@lines = <$in>;
}发布于 2011-07-28 20:36:54
有点不清楚,但这就是你想要的吗?
对于这类任务,距离算子是理想的:
#!/usr/bin/perl
my @array;
while (<DATA>) {
push @array, $_ if /ABCD/ .. 0
}
shift(@array);
print @array;
__DATA__
BCDA
ABCD
AAAABBBBCCCCDDD
AAAAAABBBBBBCCC
AAAAAAAAAAAAAA产出:
AAAABBBBCCCCDDD
AAAAAABBBBBBCCC
AAAAAAAAAAAAAAhttps://stackoverflow.com/questions/6865183
复制相似问题