in reply to Printing, analyzing binary

There are various tricksy ways of trying to count the number of zeros and ones in a byte, but a lookup table is small and simple:

my @ones = (0); push @ones, map $_ + 1, @ones for 1 .. 8; my @zeros = map 8 - $_, @ones; ... read($fh, $buf, 1) or die ...; my $val = ord($buf); printf "%08b has %s ones and %s zeros\n", $val, $ones[$val], $zeros[ +$val];

Hugo