in reply to Searching in binary files
Use a sliding window:
my @lines; $/ = \80; # assume a block size of 80 while (<$file>) { push @lines, $_; my $str = join "", @lines; if ($str =~ /searchword/) { my $loc = tell $file - pos $str; print "Found a match starting after $loc.\n"; }; if (@lines > 2) { shift @lines }; };
Instead of looking for a match in just one "line", you look for a match in the "line" and the "line" after it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Searching in binary files
by crenz (Priest) on Dec 14, 2005 at 18:25 UTC | |
by Anonymous Monk on Mar 21, 2013 at 20:19 UTC |