In Perl, how can I read an entire file into a string?
I would do it like this: my $file = “index.html”; my $document = do { local $/ = undef; open my $fh, “<“, $file or die “could not open $file: $!”; <$fh>; }; Note the use of the three-argument version of open. It is much safer than the old two- (or one-) argument versions. Also … Read more