http://www.perlmonks.org?node_id=1020214


in reply to Confusion about code sample in perlfaq4

Don't they want to get a list "e.g. ( 1, 0, 0, 1, 1, 0 ... )" as stated in the beginning of that section,

Why not just try it out?

$vec = pack 'V', int( 2**32* rand() );; print $bits;; 011000001111110110010000101101 @ints = (); { use integer; push @ints, 0 if $bits =~ s/^(\d)// && $1; push @ints, pos $bits while $bits =~ /1/g; };; print @ints;; 1 2 8 9 10 11 12 13 15 16 19 24 26 27 29

The are producing a list of the positions of the bits that are set.

I do agree that the section title and description and the sub name are woefully bad.

I'm also less than impressed with the claims for efficiency:

C:\test>perl -MMath::Random::MT=rand -minteger -MBenchmark=cmpthese $vec = pack 'V*', map int( 2**32* rand() ), 1 ..10;; cmpthese -1, { a=>q[ my @ints; my $bits = unpack 'b*', $vec; use integer; push @ints +, 0 if $bits =~ s/^(\d)// && $1;push @ints, pos $bits while($bits =~ +/1/g); ], b=>q[ my @ints = grep{ vec( $vec, $_, 1 ) } 0 .. length( $vec ) -1; ] +, };; ^Z Rate a b a 22306/s -- -79% b 108646/s 387% --

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.