Hello All, I am a PERL newbie, and come from a hardware background. My question is with regards concatenating binary data in PERL. I am reading a 32-bit value (4 bytes) from a binary file. I would like to concatenate one bit in front of the value (new value will be 33 bits!) I have tried different variations of using pack, but either I don't think I understand pack command correctly, or B, PERL doesn't like my use of a 33 bit data. How should I fix this? Here is sample of what I am doing
open (PARSER_FILE, $inputfile)
or die "Couldn't open $inputfile for reading";
binmode(PARSER_FILE);
open (OUT_FILE, ">", $outputfile)
or die "Couldn't open $outputfile for writing";
binmode(OUT_FILE);
read(PARSER_FILE, $buff, 4)
.
.
print OUT_FILE pack(b33, 1, $buff);
-
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.
|