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

后端 未结 7 2626
一向
一向 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:14

    One more answer for you to choose from:

    #!/usr/bin/env perl
    
    open(FILE, "<", "test.txt") or die("Can't open file");
    @lines = ;
    close(FILE);
    chomp(@lines);
    print join(" ", @lines);
    

提交回复
热议问题