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'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|