The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Any hints on why that happens? Because that is how array assignment works in Perl. The array expands to accommodate as many items as you assign to it. This is usually seen as a good thing as you'll discover as your experience of Perl grows. But also, think about how could perl know you only want two values to be assigned to the first array and four to the second? Perl doesn't understand the English in your variable names :) 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... Simply put, No. That would not be convenient for you at all. Even if you used the array slice assignment trick: it would be very messy to read & write; difficult to maintain; and very easy to get wrong. The simplest thing is to assign all fields to a single array and define constant names to access them:
Hopefully with better names :) But realise, that if you want to unpack two bytes as a single entity, the format C2 will not work. It will return 2 single bytes. You probably want something more like:
That is:1 unsigned byte, 1 unsigned short, 1 unsigned long, another unsigned byte; skip 400 bytes and the unpack what's left as bytes. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In reply to Re: unpack - array takes too many bytes
by BrowserUk
|
|