Syntactic Confectionery Delight | |
PerlMonks |
Re^3: Binary Comparisionby ikegami (Patriarch) |
on Feb 28, 2007 at 05:05 UTC ( [id://602451]=note: print w/replies, xml ) | Need Help?? |
There are no differences[*] between text and binary files except how you open them. Your plan would fail for text too. Consider trying to match "def\nghi" in a file whose content is "abcdef\nghijkl". You have the same problem whether the file is text (lines) or binary (blocks). The problem you really have is not text vs binary. If you solve this problem for text files, you also solve it for binary files. If you know the length of the longest signature, you could use
That's the approach I'd take if I was looking for one string. There are surely algorithms that are more efficient at search for a number of strings. * — You can even use while (<FILE>) on a binary file, but it might read more than you expect. Setting $/ to a reference to a number (e.g. $/ = \1024; and $block_size = 1024; $/ = \$block_size;) solves that.
In Section
Seekers of Perl Wisdom
|
|