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

后端 未结 7 2605
一向
一向 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:18

    If you find yourself slurping files frequently, you could use the File::Slurp module from CPAN:

    use strict;
    use warnings;
    use File::Slurp;
    
    my @lines = read_file('test.txt');
    chomp @lines;
    print "@lines\n";
    

提交回复
热议问题