How do I read the contents of a small text file into a scalar in Perl?

后端 未结 8 883
日久生厌
日久生厌 2021-01-17 17:39

I have a small text file that I\'d like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace).

The equivalent

8条回答
  •  醉酒成梦
    2021-01-17 18:07

    If I don't have Slurp or Perl6::Slurp near by then I normally go with....

    open my $fh, '<', 'file.txt' or die $!;
    
    my $whole_file = do { local $/; <$fh> };
    

提交回复
热议问题