in reply to How do I read an entire file into a string?

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; }

Replies are listed 'Best First'.
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...