--- name: pack status: documented runtime: pp source: src/runtime/pp/strings/pack.rs --- ```{index} single: pack; Perl built-in (pp runtime) ``` # pack ## Synopsis ```perl my $bin = pack("A10", "hello"); # space-padded string my $bin = pack("NnA*", $long, $short, $str); my $bin = pack("(A2)*", @pairs); # group repeat ``` ## Description Converts a list of values into a binary string according to a template. Takes a TEMPLATE string and a LIST of values and packs them into a binary string. The template is a sequence of format characters, each optionally followed by a repeat count or `*` (consume all remaining). Common format characters: - `a`, `A`, `Z` -- ASCII string (null-padded, space-padded, null-terminated) - `c`, `C` -- signed/unsigned char (8-bit) - `s`, `S` -- signed/unsigned short (16-bit native) - `l`, `L` -- signed/unsigned long (32-bit native) - `q`, `Q` -- signed/unsigned quad (64-bit native) - `n`, `N` -- unsigned short/long in network (big-endian) byte order - `v`, `V` -- unsigned short/long in VAX (little-endian) byte order - `f`, `d` -- single/double-precision float (native) - `H`, `h` -- hex string (high/low nybble first) - `w` -- BER compressed integer - `U` -- Unicode code point - `x` -- null byte padding - `X` -- back up one byte - `@` -- null-pad to absolute position - `(...)N` -- group with repeat count Whitespace and `#`-comments in templates are ignored. ## See also unpack, vec