in reply to Binary Comparision
Binary files don't necessarily have a structure similar to line breaks. The easiest way to deal with them is to read the entire file into a variable, but file size and available memory can limit this method. Reading blocks of data solves that problem, but you need to overlap on each read in case what you're looking for spans the boundary between two blocks.
Here's another approach using read.
open (FH, "$data_file); binmode FH; # set the block size as large practical # absolutely must be larger than any signature my $blocksize = 65536; # get length of largest signature my $signaturelength = ...; my $offset = 0; seek FH, $offset, 0; while (read FH, $block, $blocksize){ # check each signature against block for $signature (@def_inputs){ if (# search block for $signature){ # do signature found stuff } } # seek to next block $offset += ($blocksize - $signaturelength); seek FH, $offset, 0; } }
|
|---|