取关键字下第2行

来源:互联网 发布:法国达索软件 编辑:程序博客网 时间:2024/06/08 08:40
open( A, "<", "abc" ) || die "$!\n";  @count=();  while (<A>){      $num++;      if ($_ =~ /error/i)         {$b=$num;          print "\$b is $b\n";          open( B, "<", "abc" ) || die "$!\n";          while (<B>){          print "\$. is $.\n";          if ($. == $b + 1){print "\$_ is $_\n"};             }          #close B;           };     }; Vsftp:/root# cat -n abc     11     22     33aA     4313     5error     64234     712341     8ERROR     9666    10sdaad    11error    12313    133131 Vsftp:/root# perl a2.pl $b is 5$. is 1$. is 2$. is 3$. is 4$. is 5$. is 6$_ is 4234$. is 7$. is 8$. is 9$. is 10$. is 11$. is 12$. is 13$b is 8$. is 14$. is 15$. is 16$. is 17$. is 18$. is 19$. is 20$. is 21$. is 22$. is 23$. is 24$. is 25$. is 26$b is 11$. is 27$. is 28$. is 29$. is 30$. is 31$. is 32$. is 33$. is 34$. is 35$. is 36$. is 37$. is 38$. is 39文件句柄不关闭,会读完后继续读关闭文件句柄后Vsftp:/root# cat abc123aA313error423412341ERROR666sdaaderror3133131Vsftp:/root# perl a2.pl $_ is 12341$_ is sdaad$_ is 3131Vsftp:/root# cat a2.pl open( A, "<", "abc" ) || die "$!\n";  @count=();  while (<A>){      $num++;      if ($_ =~ /error/i)         {$b=$num;          open( B, "<", "abc" ) || die "$!\n";          while (<B>){          if ($. == $b + 2){print "\$_ is $_\n";close B;last;};             }           };     };

0 0
原创粉丝点击