Help for this page

Select Code to Download


  1. or download this
    my @bools;
    $bools[0] = 1;   # element 0 is true
    $bools[1] = '';  # element 1 is false
    
  2. or download this
    my @trues = grep $bools[$_], 0 .. $#bools;
    
  3. or download this
    my $bools;
    vec( $bools, 0, 1 ) = 1;  # element 0 is true
    vec( $bools, 1, 1 ) = 0;  # element 1 is false
    
  4. or download this
    my @trues = grep vec( $bools, $_, 1 ), 0 .. 8 * length $bools;
    
  5. or download this
    foreach my $i ( 0 .. 8 * length $bools ) {
        push @trues, $i if vec( $bools, $i, 1 );
    }
    
  6. or download this
    # for each character, count the on bits in that character
    my %bits_in;
    ...
    
    my $count;
    $count += $bits_in{ $1 } while ( $bools =~ m{([^\000])}g );
    
  7. or download this
    my $count;
    $count += $bits_in{ chop $bits } while $bits;
    
  8. or download this
    my $count;
    $count += $bits_in{ substr $bits, $_, 1 } for 0 .. length( $bits ) - 1
    +;
    
  9. or download this
    use Benchmark qw( cmpthese );
    
    ...
    
        return $bits;
    }