I suggest making friends with pack and unpack -- there's the tutorial.
A smattering of things which may not be obvious:
the pack/unpack TEMPLATE string is evaluated at run-time, so it can be dynamic -- you can, for example, interpolate repeat counts into one, or build a string depending on what you are packing/unpacking.
C is the way to handle bytes as individual integers (0..255) -- but watch out if you have 'utf8' ("wide character") strings to unpack.
a is the way to handle sections of arbitrary byte values.
in unpack you can use x to skip past bytes, and you can use @ to step to particular positions in the input.
the construct C/a*, and all its cousins, is very useful where you have data prefixed by its length in bytes
you can bracket stuff in pack/unpack templates, and apply repeat counts to bracketted sections (and nest bracketted sections). So: '(C/(NnnN2)(a4)2)*' unpack as many items as it can ( '(.....)*'), where each item comprises: a byte count followed by that many NnnN2 elements, followed by 2 elements each of 4 bytes.
In reply to Re: How to capture data length from the record ?
by gone2015
in thread How to capture data length from the record ?
by bh_perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |