[Chapter 15] 15.10 Structure Conversion
Author: Stephen Spainhour and Valerie Quercia
Date: Fri Aug 29 18:13:07 1997

#

| Chapter 15 Perl Quick Reference |

## 15.10 Structure Conversion

`pack` template, list

  Packs the values into a binary structure using template.

`unpack` template, expr

  Unpacks the structure expr into an array, using template.

template is a sequence of characters as follows:

a | / | A | ASCII string, null- / space-padded
b | / | B | Bit string in ascending / descending order
c | / | C | Native / unsigned char value
f | / | d | Single / double float in native format
h | / | H | Hex string, low / high nybble first.
i | / | I | Signed / unsigned integer value
l | / | L | Signed / unsigned long value
n | / | N | Short / long in network (big endian) byte order
s | / | S | Signed / unsigned short value
u | / | p | Uuencoded string / pointer to a string
v | / | V | Short / long in VAX (little endian) byte order
x | / | @ | Null byte / null fill until position
X |  |  | Backup a byte

Each character may be followed by a decimal number that will be used as a repeat count; an asterisk (*) specifies all remaining arguments. If the format is preceded with %n, `unpack` returns an n-bit checksum instead. Spaces may be included in the template for readability purposes.

Conversion Functions |  | String Functions