open my $fp,'<',$file or die $!; while (<$fp>) { my $line = $_; if ($line =~ /$regex/) { # How do I find out which line number this match happened at? } } close $fp;
解决方法
使用$。 (见
perldoc perlvar
)。
open my $fp,'<',$file or die $!; while (<$fp>) { my $line = $_; if ($line =~ /$regex/) { # How do I find out which line number this match happened at? } } close $fp;
perldoc perlvar
)。