[Israel.pm] binary vectors representation

Shlomi Fish shlomif at iglu.org.il
Fri Jun 11 04:42:38 PDT 2004

On Friday 11 June 2004 13:48, Shlomo Yona wrote:
> Hello,
> 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?

Actually, Perl has a vec() function (perldoc -f vec) to handle bit vectors. 
There are also several modules on CPAN for it. (like Bit::Vector)

I don't think pack and unpack are applicable here, but they might. In any 
case, it seems vec is the way to go.


	Shlomi Fish

> Thanks.


Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://shlomif.il.eu.org/

Quidquid latine dictum sit, altum viditur.
        [Whatever is said in Latin sounds profound.]

More information about the Perl mailing list