Here is a small example using PDL. I read 7,500,000 bytes into a flat array and use slice indexing to find the right bytes to mask against.
use strict;
use IO::File;
use PDL;
use PDL::IO::FlexRaw;
use PDL::NiceSlice;
my $fn = "survey.dat";
my $fh = new IO::File($fn,"r");
my $width = 3000/8;
my $height = 20000;
my $total = $width*$height;
# Read it all in as one flat file for simplicity.
my $pdl = readflex $fh, [{Dims=>[$total], Type=>'byte'}];
# For example, find which items have bit 4 set in the
# 7th byte and bit 3 set in the 20th byte.
my $m1 = 1 << 4;
my $m2 = 1 << 3;
my $b1 = 7;
my $b2 = 20;
# Which record numbers contain the given one-bits?
# Take slices with a width of 3000/8 = 375.
$total = $total - 1;
my $s1 = $pdl($b1:$total:$width);
my $s2 = $pdl($b2:$total:$width);
my $index = which((($s1 & $m1) > 0) & (($s2 & $m2) > 0));
print $index;
|