in reply to Re^3: Possible to have regexes act on file directly (not in memory)
in thread Possible to have regexes act on file directly (not in memory)

In principle this seems to work. Here's an example:

use strict; use warnings; use Sys::Mmap; my $string; open my $fh, '<', '/usr/share/dict/words' or die $!; Sys::Mmap::mmap( $string, 0, MAP_SHARED, PROT_READ, $fh ); while( $string =~ m/^(wal.*)$/mg ) { print $1, "\n"; } Sys::Mmap::munmap( $string ) or die "munmap: $!"; close $fh;

On my system I get a dump of everything in the dict/words file starting with 'wal'. However, I end up getting the following error message when munmap is called:

variable is not a string at ./mytest.pl line 17.

The XS code testing whether the variable being unmapped is a string is this:

if(SvTYPE(var) != SVt_PV) { croak("variable is not a string"); return; }

...which doesn't strike me as wrong. Must be something in the XS for 'mmap' that is not happening properly.


Dave