while ($mmap =~ m/^([^\n]*$pat[^\n]\n)/omg)
{
print $1;
}
####
while ($mmap =~ m/$pat/omg)
{
my $pos = pos $mmap;
# Find the beginning and end of this line
my $first = rindex($mmap,"\n",$pos)+1;
my $last = index($mmap,"\n",$pos)+1;
print substr($mmap,$first,$last-$first);
}
####
#!/usr/bin/perl
use warnings;
use strict;
use Sys::Mmap;
our $pat = shift;
foreach my $a (@ARGV)
{
my $mmap;
if (! -f $a)
{
warn "'$a' is not a regular file, skipping\n";
next;
}
open(F, "< $a")
or die "Couldn't open '$a': $!\n";
mmap($mmap, 0, PROT_READ, MAP_SHARED, F)
or die "mmap error: $!\n";
while ($mmap =~ m/^([^\n]*$pat[^\n]\n)/omg)
{
print $1;
}
munmap($mmap)
or die "mmunmap error: $!\n";
close(F)
or die "Couldn't close '$a': $!\n";
}