[Israel.pm] binary vectors representation

Shlomo Yona shlomo at cs.haifa.ac.il
Fri Jun 11 03:48:05 PDT 2004


I have strings in @strings, each is a scalar of length
$vector_size (vector size is a fixed value detremined up
front and is normally somewere between 30000-50000).

I'm storing the strings in a text file, one string per line.
This means that each line is of length $vector_size+1 (the
extra character is due to the newline character).

The characters making the strings are only '0' and '1'. This
makes the strings "binary vectors".

I'd like to store the vectors more compactly, using bit
representation. I'd also like to be able to easily convert
the strings to binary format, storing them in a file and
later on be able to easily extract them one by one from a
file and reconstruct them as strings, or as arrays.

It seems that the tools to use here are 'pack' and 'unpack',
however, I'm not sure which template to use, and also, I'm
not sure how to store the binary data to a file and later on
read it from a file.

What would be the idioms to use here?


Shlomo Yona
shlomo at cs.haifa.ac.il

More information about the Perl mailing list