Search notes:

Perl module File::Slurp

use warnings;
use strict;

use File::Slurp;

#
#  Read file into string (scalar context).
#
my $file_text=read_file(__FILE__); 
print $file_text;

#
#  Read file into array (list context).
#
my @file_lines=read_file(__FILE__); 
print join ". ", @file_lines;

#
#  Write a file (write this script in uppercase letters)
#
write_file('file.out', map { uc } @file_lines);
Github repository PerlModules, path: /File/Slurp/script.pl

write_file.pl

use warnings;
use strict;

use File::Slurp;

my $file_name = 'written_file.txt';

unlink $file_name if -f $file_name;

my @lines = (
  "foo bar baz\n",
  "one two three\n",
  "1 2 3 4 5 6 7 8 9\n"
);

write_file($file_name, @lines);
Github repository PerlModules, path: /File/Slurp/write_file.pl

sysread() is deprecated on :utf8 handles. This will be a fatal error in Perl 5.30 at /usr/share/perl5/site_perl/File/Slurp.pm line

Unfortunately, I got this error message when I used File::Slurp. When googling around about that, I found a few writers that said that File::Slurper should be used instead of File::Slurp.

See also

File::Slurper, Path::Tiny, IO::All, use Mojo::Util qw(slurp).
Perl modules
The .NET method System.IO.File::ReadAllText

Index