vr has asked for the wisdom of the Perl Monks concerning the following question:
I'm confused about code sample from here:
How do I manipulate arrays of bits?
They say:
...given a vector in $vec , you can get those bits into your @ints array:
and give following code as "fast general algorithm"
use integer; my $bits = unpack "b*", $vec; push @ints, 0 if $bits =~ s/^(\d)// && $1; push @ints, pos $bits while($bits =~ /1/g);
What are they trying to do with two lines starting with push operators? Don't they want to get a list "e.g. ( 1, 0, 0, 1, 1, 0 ... )" as stated in the beginning of that section, i.e. do reverse conversion? They can't do it with this code, do they?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Confusion about code sample in perlfaq4
by BrowserUk (Patriarch) on Feb 22, 2013 at 19:50 UTC | |
by vr (Curate) on Feb 22, 2013 at 23:26 UTC | |
by BrowserUk (Patriarch) on Feb 23, 2013 at 06:25 UTC | |
|
Re: Confusion about code sample in perlfaq4
by thundergnat (Deacon) on Feb 22, 2013 at 19:36 UTC |