map_handle#

Attach an already-open filehandle to a scalar as a memory map.

Σύνοψη#

open my $fh, '<:raw', $filename;
map_handle my $map, $fh;
map_handle my $map, $fh, '+<', $offset, $length;

Ορίσματα#

  • $lvalue - scalar to receive the mapping.

  • $filehandle - a real filehandle. Scalar-string handles and tied handles are rejected.

  • $mode - defaults to '<'. Same accepted values as map_file.

  • $offset, $length - same meaning and defaults as map_file.

Παραδείγματα#

Map the tail of a log file:

open my $fh, '<:raw', '/var/log/syslog' or die $!;
my $size = -s $fh;
map_handle my $tail, $fh, '<', $size - 4096, 4096;

Οριακές περιπτώσεις#

  • The filehandle must be binary. Encoding layers like :utf8 or :crlf cause map_handle to reject the handle.

  • The handle must refer to a regular file, block device, or character device. Pipes and sockets cannot be mapped.

  • The handle stays valid after the call; closing it does not invalidate the mapping.

Διαφορές από το upstream#

Fully compatible with upstream File::Map 0.71.

Δείτε επίσης#

  • map_file - take a filename instead of a filehandle.

  • sys_map - pass raw mmap(2) flags directly.

  • unmap - release the mapping before scope exit.