Perl获取匹配行的最后三行

#!/usr/bin/perl
open (file,"D:\\OUTCAR");
$a=0;
while ($lines=<file>){
if ($lines=~/TOTAL ELASTIC/){
$lines_number=$.;
$a=1
}
if ($a==1){
sub1()
}
}
close(file);
sub sub1{
if (grep {$.==$_}$lines_number..$lines_number+10){
print "$lines";
}else{
$a=2;
}
}

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