Dear Monks,

Having settled this issue of unpacking the "records" part of a binary file, I now tackle its "header" (or part of its header).

($name, $onebyte, @twobytes, @fourbytes, $back2onebyte, @trailing) = unpack( "Z16 C1 C2 C4 C1 x400 C*", $data );

The @twobytes array swallows all remaining bytes of the file, not just the 2 is am seeking. The next variables remain of course undefined. Any hints on why that happens?

For a secondary question (once I can solve the first issue), I'll mention I have over 50 variables of varying size in that header. Am I on a valid approach by appending them in the above statement? That will end up being one looong statement...

Again I am very thankful for any hints as well as for your indulgence in case I am missing the obvious

Update
Thanks for very very informative answers, and BrowserUK's suggested use of constant works really nicely! ++ too all!! Update2: enum mentioned later could be a fabulous time saver as well, but I could not find a way to use it with anything else than scalars.

In reply to unpack - array takes too many bytes by jjap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.