Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Answer: How do I read an entire file into a string?

( #180509=categorized answer: print w/ replies, xml ) Need Help??

Q&A > files > How do I read an entire file into a string? contributed by particle

nothing i know beats this for speed. there's a node on this technique somewhere around here...

my $file = 'sample.txt'; { local *FH; -f FH and sysread FH, my $file, -s FH; }

Comment on Answer: How do I read an entire file into a string?
Download Code
Re: Answer: How do I read an entire file into a string?
by cadphile (Beadle) on Aug 11, 2014 at 21:09 UTC
    Don't see how this works. This must just be a fragment. Seems like you need at least this much:
    my $file = 'sample.txt'; my $buf; { local *FH; open FH, "$file" or die $!; -f FH and sysread FH, $buf, -s FH; }
    results are in $buf after the read...

    Unless you meant to write to sample.txt in the first place, and FH was just presumed open to some readable file...

    thanks,
    -Cadphile...

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-10-30 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls