http://qs321.pair.com?node_id=516720


in reply to Re: Searching in binary files
in thread Searching in binary files

Danke nach Frankfurt!

There are a few bugs in your code, though. I changed the if to a while loop and fixed a few other problems:

while ($str =~ /searchword/g) { my $loc = tell($fh) - length($str) + pos($str); print "Found a match starting after $loc.\n"; }

Update: That doesn't quite work either... it finds too many occurrences...

Replies are listed 'Best First'.
Re^3: Searching in binary files
by Anonymous Monk on Mar 21, 2013 at 20:19 UTC
    while ($str =~ /$pattern/g) { my $loc = tell($fh) - length($str) + pos($str) - length($patte +rn); print "Found a match starting after $loc.\n"; }