http://qs1969.pair.com?node_id=946331

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have some large (multiple million bits) bit vectors, and I'd like to run length encode them to save storage.

Given the input: my $bv = pack 'N', 0x01020304; I'd like to get out an array

-1, 9, -1, 6, -2, 8, -1, 5

Where negative counts represent set bits and positive counts clear bits.

Searches for Perl and run length encoding all seem to turn up the rosetta stone thing of RLE strings: '"wwwbbbw" => 'w3b3w1' using regex.

I know I need to use vec(), but I keep getting lost in the state changes and end up with huge nest of ifs and garbage output.

Any help appreciated.