in reply to Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };
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
or, better if lexical filehandles are available,my $string = do { local $/; open local(*FILEHANDLE), 'somefile.txt' or die $!; <FILEHANDLE> };
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.my $string = do { local $/; open my $fh, 'somefile.txt' or die $!; <$fh> };
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };
by Zaxo (Archbishop) on Sep 03, 2003 at 02:42 UTC | |
Re: Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };
by John M. Dlugosz (Monsignor) on Sep 02, 2003 at 20:30 UTC |