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
1 1
2 2
3 3aA
4 313
5 error
6 4234
7 12341
8 ERROR
9 666
10 sdaad
11 error
12 313
13 3131
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 abc
1
2
3aA
313
error
4234
12341
ERROR
666
sdaad
error
313
3131
Vsftp:/root# perl a2.pl
$_ is 12341
$_ is sdaad
$_ is 3131
Vsftp:/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;};
}
};
};