pack
pack template, list
Takes a list of values and packs it into a binary
structure, returning the string containing the structure.
template
is a sequence of characters
that give the order and type of values, as follows:
Character | Meaning |
---|---|
| Null-fill to absolute position. |
| Start of a |
| An ASCII string, will be null padded. |
| An ASCII string, will be space padded. |
| A bit string, low-to-high order (such as
|
| A bit string, high-to-low order. |
| A signed char value. |
| An unsigned char value. |
| A double-precision float in the native format. |
| A long double-precision float in the native format. Long doubles are avai able only if your system supports long double values and if Perl has been compiled to support these values. Causes a fatal error otherwise. New in 5.8. |
| A single-precision float in the native format. |
| A floating-point value in the native format, i.e., a Perl internal floating-point value (NV). New in 5.8. |
| A hexadecimal string, low nybble first. |
| A hexadecimal string, high nybble first. |
| A signed integer value. |
| An unsigned integer value. |
| A signed long value. |
| A signed integer value, i.e., a Perl internal integer (IV). New in 5.8. |
| An unsigned integer value, i.e., a Perl internal unsigned integer (UV). New in 5.8. |
| An unsigned long value. |
| A short in “network” (big-endian) order. |
| A long in “network” (big-endian) order. |
| A pointer to a string. |
| A pointer to a structure (fixed-length string). |
| A signed quad (64-bit) value. New in 5.8. |
| An unsigned quad value. Quads are available only if your system supports 64-bit integer values and if Perl has been compiled to support these values. Causes a fatal error otherwise. New in 5.8. |
| A signed short value. |
| An unsigned short value. |
| A short in “VAX” (little-endian) order. |
| A long in “VAX” (little-endian) order. |
| A uuencoded string. |
| A Unicode character number. Encodes to UTF-8 internally (or UTF-EBCDIC in EBCDIC platforms). New in 5.8. |
| A BER compressed integer. |
| A null byte. |
| Back up a byte. |
| A null terminated (ASCII) string. Will be null padded. New in 5.8. |
Each character may optionally be followed by a number that
gives a repeat count. Together the character and the repeat count
make a field specifier. Field specifiers may be separated by
whitespace, which will be ignored. With all types except a
and A
, the pack
function will gobble up that many
values from the list
. Specifying
*
for the repeat count means to
use however many items are left. The a
and A
types gobble just one value, but pack
it as a string of length count
, padding
with nulls or spaces as necessary. (When unpacking, A
strips trailing spaces and nulls, but
a
does not.) Real numbers
(floats and doubles) are in the native machine format only; due to
the multiplicity of floating formats, and the lack of a standard
network representation, no facility for interchange has been
made.
Generally, the same template may also be used in the
unpack
function. If you want to
join variable length fields with a delimiter, use the join
function.
3.147.27.131