Chapter 19. Structure Conversion
- pack template, list
Packs the values in list into a sequence of bytes, using the specified template. Returns this sequence as a string.
- unpack template, expr
Unpacks the sequence of bytes in expr into a list, using template.
template is a sequence of characters as follows:
Byte string, null-/space-padded
Bit string in ascending/descending order
Signed/unsigned byte value
Native double/long double
Native float/Perl internal float
Hex string, low/high nybble first
Signed/unsigned integer value
Perl internal integer/unsigned
Signed/unsigned long value
Short/long in network (big endian) byte order
Pointer to a null-terminated/fixed-length string
Signed/unsigned quad value
Signed/unsigned short value
Uuencoded string/Unicode UTF-8 character code
Short/long in VAX (little endian) byte order
A BER compressed integer
Null byte (skip forward)/Back up a byte
Null-terminated string/null fill to position
The size of an integer, as used by
I, depends on the system architecture. Nybbles, bytes, shorts, longs, and quads are always exactly 4, 8, 16, 32, and 64 bits respectively. Characters
L may be followed by a
! to signify native shorts and longs instead.
X may be followed by a
! to specify alignment.
Each character, or group of characters between parentheses, may be followed by a decimal number, optionally between
], that will be used as a repeat count; an asterisk ( ...