in reply to Re^2: why the unpack doesnt split the data to the array ?
in thread why the unpack doesnt split the data to the array ?

What do you think that the C5 does? You use it, and it returns 5 (byte) numbers. It is equivalent to a byte[5] I guess. Maybe you can describe to us what you intend it to do, then we can tell you what other template you should use. Because your "according to the template" is how Perl already behaves. But that does not seem to be what you want.

Replies are listed 'Best First'.
Re^4: why the unpack doesnt split the data to the array ?
by gyre007 (Novice) on Aug 06, 2008 at 19:20 UTC
    well as you can from the code snippet at the beginning:
    @data = unpack('C C C C C C C C C C3 C3 C5 C5 C3 C3 C3 C C3 C C12 C20' +, $buffer);
    So I would expect that @data array would contain 21 items...each item should be as long as it is specified in the template so C - means ONE unsigned char , C5 - FIVE unsigned chars and so on... so I would like the data in $buffer to be unpacked into these 21 items (f0, ..., last twenty bytes - since the last template says C20) That is what I want...SPLIT THE DATA into the @data array...
      Oh! I think you want arrays! You didn't mention arrays at all. Pack can't do that, but the following can:
      @data = unpack('C C C C C C C C C A3 A3 A5 A5 A3 A3 A3 C A3 C A12 A20' +, $buffer); $_ = [ unpack('C*', $_) ] for @data[9, 10, 11, 12, 13, 14, 15, 17, 19, + 20];

      Update: Forgot to specify index. Fixed.