What's the best way to open and read a file in Perl?

前端 未结 12 2049
醉话见心
醉话见心 2020-11-27 13:11

Please note - I am not looking for the \"right\" way to open/read a file, or the way I should open/read a file every single time. I am just interested to find out what way m

12条回答
  •  孤街浪徒
    2020-11-27 13:18

    I once used the

    open (FILEIN, "<", $inputfile) or die "...";
    my @FileContents = ;
    close FILEIN;
    

    boilerplate regularly. Nowadays, I use File::Slurp for small files that I want to hold completely in memory, and Tie::File for big files that I want to scalably address and/or files that I want to change in place.

提交回复
热议问题