PerlIO::mmap#
📦 min
The :mmap PerlIO layer: read a file through a memory mapping instead of read(2) calls.
open my $fh, '<:mmap', $file or die "open: $!";
my @lines = <$fh>;
print join(",", PerlIO::get_layers($fh)), "\n"; # unix,perlio,mmap
On the first read the layer maps the rest of the file, from the current position to its end, and reads come straight out of the mapping instead of being copied into a buffer. Only a regular file is mapped; anything else (a pipe, a terminal) reads as an ordinary buffered handle, and writing always goes through an ordinary buffer. Nothing needs to be loaded: naming the layer in open or binmode loads it.
This is a native implementation of PerlIO::mmap 0.017.
Differences from upstream#
None.