Read entire file

my $string = slurp 'sample.txt';

The default encoding is UTF-8. The :enc adverb can be used to specify a different one:

my $string = slurp 'sample.txt', :enc<UTF-16>;

IO::Path objects also provide slurp as a method:

my $string = 'sample.txt'.IO.slurp;

Last updated