Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved slurping idiom per Ruud H. G. van Tol.

  • Loading branch information...
commit 61460b841819f1ac777b774aa54cf6c0f2490a0b 1 parent 7e54768
chromatic chromatic authored
Showing with 10 additions and 0 deletions.
  1. +3 −0  CREDITS
  2. +7 −0 sections/idioms.pod
@@ -239,3 +239,6 @@ E:
N: Kirk Kimmel
+N: Ruud H. G. van Tol
7 sections/idioms.pod
@@ -252,6 +252,10 @@ files into a scalar in a single expression:
my $file = do { local $/; <$fh> };
+ # or
+ my $file; { local $/; $file = <$fh> };
=end programlisting
C<$/> is the input record separator. C<local>izing it sets its value to
@@ -266,6 +270,9 @@ end of the block, C<$file> now contains the contents of the file.
The second example contains no assignment and merely returns the single line
read from the filehandle.
+The third example avoids a second copy of the string containing the file's
+contents; it's not as pretty, but it uses the least amount of memory.
=begin tip C<File::Slurp>
X<CPAN; C<File::Slurp>>
Please sign in to comment.
Something went wrong with that request. Please try again.