How to get the current line number of a file open using Perl?

前端 未结 3 2024
不思量自难忘°
不思量自难忘° 2021-01-03 19:21
open my $fp, \'<\', $file or die $!;

while (<$fp>) {
    my $line = $_;
    if ($line =~ /$regex/) {
        # How do I find out which line number this mat         


        
3条回答
  •  走了就别回头了
    2021-01-03 19:59

    You can also do it through OO interface:

    use IO::Handle;
    # later on ...
    my $n = $fp->input_line_number();
    

    This is in perldoc perlvar, too.

提交回复
热议问题