Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: Load file into a scalar without File::Slurp

by audreyt (Hermit)
on Jul 25, 2000 at 01:25 UTC ( #24191=note: print w/ replies, xml ) Need Help??


in reply to Load file into a scalar without File::Slurp

I usually use this Perl Golf-ish subroutine that doesn't require a filehandle:

$contents=slurp('foobar'); sub slurp {local$/=<>if local@ARGV=@_}
or use an in-line block:
{local$/;$contents=<>if local@ARGV='foobar'};
or, if you could afford a filehandle and wasted CPU time:
$contents=join'',<_>if open _,'foobar';
Of course, if this is really a Perl Golf contest entry, I'll probably write:
$contents=`cat foobar`
But it's platform dependent and cheating, so don't do that. :-p

/Autrijus/


Comment on RE: Load file into a scalar without File::Slurp
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-08-27 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (253 votes), past polls