develooper Front page | perl.perl5.porters | Postings from October 2014

experimental mmap snarf (aka slurp) patch

Thread Next
From:
Jarkko Hietaniemi
Date:
October 8, 2014 20:12
Subject:
experimental mmap snarf (aka slurp) patch
Message ID:
54359AAF.3030009@iki.fi
I quickly hacked together a patch to try out mmap() in sv_gets()
for the "snarfing" where a filehandle is read wholesale into a scalar.
In Perl parlance this is also known as "slurping".

Practically untested except for the basic scenario:

open my $fh, $fn; my $data = do { local $/; <$fh> }

Handles the (odd) case of not being in the beginning of the handle.
Probably leaks something or does something equally stupid.

Right now I have no time to test/benchmark (and the aggressive caching
by operating systems makes this a very thankless task indeed) but in
case someone else is, please find the patch is attached.  For science.




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About