<?xml version="1.0" encoding="windows-1252"?>
<node id="287686" title="Re: Perl Idioms Explained - my $string = do { local $/; &lt;FILEHANDLE&gt; };" created="2003-08-29 10:52:05" updated="2005-07-07 15:23:04">
<type id="11">
note</type>
<author id="82147">
Zaxo</author>
<data>
<field name="doctext">
&lt;p&gt;It may be useful to restrict the scope of the file handle as well, since slurping is a one pass approach. That may be done with
&lt;code&gt;my $string = do {
    local $/;
    open local(*FILEHANDLE), 'somefile.txt' or die $!;
    &lt;FILEHANDLE&gt;
};&lt;/code&gt;
or, better if lexical filehandles are available,
&lt;code&gt;my $string = do {
    local $/;
    open my $fh, 'somefile.txt' or die $!;
    &lt;$fh&gt;
};&lt;/code&gt;
since the lexical handle is properly closed when it goes out of scope. Either way ensures no interference with other handles of the same name.&lt;/p&gt;
&lt;p&gt;After Compline,&lt;br/&gt;Zaxo&lt;/p&gt;</field>
<field name="root_node">
287647</field>
<field name="parent_node">
287647</field>
</data>
</node>
