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

后端 未结 7 2476
一向
一向 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:08

    This is the code that do this (assume the below code inside script.pl) :

    use strict;
    use warnings
    my @array = <> ;
    chomp @array;
    print "@array";
    

    It is run by:

    scirpt.pl [your file]
    

提交回复
热议问题