Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

by pbeckingham (Parson)
on Mar 10, 2004 at 19:01 UTC ( #335562=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };
in thread Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

I have been using

my $slurp = join '', <FH>;
as well, but having had the idiom explained to me, I realize that this approach is potentially doing more work than the idiom. It makes sense to me that reading from a file handle in list context causes a list to be returned, which is then collapsed by the join, and that this approach is probably not as efficient.

I assume that the idiom is achieving this down in the (fast) IO layer, and the cost of the block, and the localized variable are lower.


Comment on Re: Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-08-23 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls