How can I read lines from the end of file in Perl?

后端 未结 11 1957
夕颜
夕颜 2020-12-06 02:41

I am working on a Perl script to read CSV file and do some calculations. CSV file has only two columns, something like below.

One Two
1.00 44.000
3.00 55.000         


        
11条回答
  •  情书的邮戳
    2020-12-06 03:26

    You could use Tie::File module I believe. It looks like this loads the lines into an array, then you could get the size of the array and process arrayS-ze-1000 up to arraySize-1.

    Tie::File

    Another Option would be to count the number of lines in the file, then loop through the file once, and start reading in values at numberofLines-1000

    $count = `wc -l < $file`;
    die "wc failed: $?" if $?;
    chomp($count);
    

    That would give you number of lines (on most systems.

提交回复
热议问题