Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 studying the Monastery: (8)
As of 2014-12-21 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls