Perl获取匹配行之后的后几行2

#!/usr/bin/perl
open (f,"D:\file");
while ($lines=<f>){
if ($lines=~/TOTAL ELASTIC/){
$line_number=$.;
$line_control=1;
}
next if ($line_control==0);#next后面的不执行,直接跳到循环开始的地方,相当于python中contiue
print "$lines",if (grep {$.==$_}$line_number..$line_number+10);#遍历后面列表中的每个元素是不是和$.相等,就相当于检查$.是不是在列表中
}
$a=<STDIN>;
#关于grep可以详细参看手册
=pod
grep{$_%2}1..100
grep会先遍历1..100中的每个元素,将其%2,如果结果结果为真就返回true
=cut

原文地址:https://www.cnblogs.com/shunguo/p/11441678.html