in reply to Working with Binary Numbers

brute force but non-recursive:
my @data = qw( 000- 0101 011- 1-0-); my @bin; while (@data) { my $data = shift @data; if ($data =~ tr/-//) { my ($zero, $one) = ($data, $data); $zero =~ s/-/0/; $one =~ s/-/1/; unshift @data, $zero, $one; } else { push @bin, $data; } } print "@bin\n";
and anyway, what is your real problem? for a big subset of the ones I can imagine, maintaining your data as a list of numbers and masks can be a better solution than actually expanding the data set.

Replies are listed 'Best First'.
Re^2: Working with Binary Numbers
by shoness (Friar) on Sep 25, 2007 at 13:40 UTC
    No worries, you're right. Most of the time I keep data in the more compact form, but sometimes I've got to expand it to actually work on the real bit vectors.

    I understand your example right away as well. map-a-glob is elegant but people know I didn't write it and can't maintain it. :-)