in reply to Fastest Search method for strings in large file
use strict; use warnings; use Mmap; open my $file, '<', 'big21gfilename.ext' or die; mmap my $f, 0, PROT_READ, MAP_SHARED, $file or die; my $re = '('+join('|',@ARGV)+')'; $re = qr($re); printf "%d: %s\n", pos($f), $1 while $f =~ /$re/g;
unless, of course, your file has lines, in which case
will probably be faster.use strict; use warnings; my $re = '('+join('|',@ARGV)+')'; $re = qr($re); open my $file, '<', 'big21gfilename.ext' or die; while( <$file> ) { printf "%d (%d): %s\n", $., pos, $1 while /$re/g }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fastest Search method for strings in large file
by BrowserUk (Patriarch) on Jul 14, 2008 at 15:00 UTC |