3 ms·
Slightly more idiomatic would be with a useful die (and a semicolon terminating the first line): open(my $fh, "<", "file.txt") or die "Error reading file: $!
by mapgrep 15y ago
Slightly more idiomatic would be with a useful die (and a semicolon terminating the first line):
open(my $fh, "<", "file.txt") or die "Error reading file: $!";
my @lines = <$fh>;
To slurp into a string rather than an array of lines:
open(my $fh, "<", "file.txt") or die "Error reading file: $!";
my $s = join('',<$fh>);