News for hackers. Stuff that matters.
Re:Python for Perl programmers by lawn on Tuesday April 03, 2012 @03:07PM (#3794306)
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.

There are no comments on this comment yet.