Best way to skip a header when reading in from a text file in Perl?

后端 未结 7 1624
难免孤独
难免孤独 2021-02-01 10:16

I\'m grabbing a few columns from a tab delineated file in Perl. The first line of the file is completely different from the other lines, so I\'d like to skip that line as fast a

7条回答
  •  轮回少年
    2021-02-01 11:02

    Your code would probably be more elegant in this form:

    my $first;
    while (...) {
        $first++ or next; 
    
        # do whatever you want
    };
    

    But it's still fine. @Guru's answer is better in terms of CPU cycles, but i/o usually consumes orders of magnitude more of them than a single if.

提交回复
热议问题