The code you provided is missing a step before the pack function. tr/ \t/01/; is needed to translate the spaces and tabs to 0's and 1's before pack can turn them into text.
Not so. The 'b' and 'B' pack templates only look at the least-significant bit of a character to be packed, so space (0x20) and '0' (0x30) translate | pack to a 0 bit, and \t (0x09) and '1' (0x31) to a 1 bit.
c:\@Work\Perl\monks>perl -wMstrict -le
"for my $s (qq{\t \t \t \t }, '1000001001000010', 'qpppppqppqp
+pppqp') {
my $p = pack 'b*', $s;
print qq{'$s' -> '$p'};
}
"
' ' -> 'AB'
'1000001001000010' -> 'AB'
'qpppppqppqppppqp' -> 'AB'
|