How can I read the lines of a file into an array in Perl?

后端 未结 7 2578
一向
一向 2021-02-20 12:22

I have a file named test.txt that is like this:

Test
Foo
Bar

But I want to put each line in a array and pri

7条回答
  •  后悔当初
    2021-02-20 13:04

    This is the simplest version I could come up with:

    perl -l040 -pe';' < test.txt
    

    Which is roughly equivalent to:

    perl -pe'
      chomp; $\ = $/; # -l
      $\ = 040;       # -040
    '
    

    and:

    perl -e'
      LINE:
        while (<>) {
          chomp; $\ = $/; # -l
          $\ = " ";       # -040
        } continue {
          print or die "-p destination: $!\n";
        }
    '
    

提交回复
热议问题