#!/usr/bin/perl
Hi !
I have a little question concerning unpack function
I have a binary file, from which I read blocks of 71 bytes (in binmode).
I want then unpack the data using unpack function but I somehow don't get its functionality...as I understand it It should return an array containing unpacked data according to the given template..
What I do is to read block of data
open INF, $FileName or die "\nCan't open $FileName for reading: $!\n";
binmode INF;
while ( ($readBytes = read (INF, $buffer, BLOCK_SIZE )) ){
print 'Read bytes:'.$readBytes."\n";
$BlockCounter++;
@data = unpack('C C C C C C C C C C3 C3 C5 C5 C3 C3 C3 C C3 C C12
+C20', $buffer);
$tmp = @data;
print "Size of DataArray = $tmp\n";
}
What I don't understand is why the size of the array is not equal to the number of templates in template string passed to unpack function but it is still 71 items big as it is the size of the read block(BLOCK_SIZE = 71).
I thought unpack works the way as I wrote it, but I was terribly wrong...
Can anyone help me with this ?
Otherwise I will just have to use substr functions to cut the buffer into such long parts I need ?
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.