3 ms·
my $txt = do { local $/ = <$file>; }; or my $txt = do { local $/; <$file>; }; are as I know the preferred ways to do it. As a previous comment explained, $/
by lawn 15y ago
my $txt = do { local $/ = <$file>; };
or
my $txt = do { local $/; <$file>; };
are as I know the preferred ways to do it. As a previous comment explained, $/ is the record separator and when you localize it it's value is set to undef. Which means we read the whole filehandle (the second part). As a do block evaluates to the value of the last expression, the contents of the file is the result of the whole expression.
If you're serious about Perl I recommend Modern Perl which is a 250 page really good introduction for the language, intended for programmers.