- or download this
my @bools;
$bools[0] = 1; # element 0 is true
$bools[1] = ''; # element 1 is false
- or download this
my @trues = grep $bools[$_], 0 .. $#bools;
- or download this
my $bools;
vec( $bools, 0, 1 ) = 1; # element 0 is true
vec( $bools, 1, 1 ) = 0; # element 1 is false
- or download this
my @trues = grep vec( $bools, $_, 1 ), 0 .. 8 * length $bools;
- or download this
foreach my $i ( 0 .. 8 * length $bools ) {
push @trues, $i if vec( $bools, $i, 1 );
}
- 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 );
- or download this
my $count;
$count += $bits_in{ chop $bits } while $bits;
- or download this
my $count;
$count += $bits_in{ substr $bits, $_, 1 } for 0 .. length( $bits ) - 1
+;
- or download this
use Benchmark qw( cmpthese );
...
return $bits;
}