O'Reilly logo

Perl Pocket Reference, 5th Edition by Johan Vromans

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

a / A

Byte string, null-/space-padded

b / B

Bit string in ascending/descending order

c / C

Signed/unsigned byte value

d / D

Native double/long double

f / F

Native float/Perl internal float

h / H

Hex string, low/high nybble first

i / I

Signed/unsigned integer value

j / J

Perl internal integer/unsigned

l / L

Signed/unsigned long value

n / N

Short/long in network (big endian) byte order

p / P

Pointer to a null-terminated/fixed-length string

q / Q

Signed/unsigned quad value

s / S

Signed/unsigned short value

u / U

Uuencoded string/Unicode UTF-8 character code

v / V

Short/long in VAX (little endian) byte order

w

A BER compressed integer

W

Unsigned character value

x / X

Null byte (skip forward)/Back up a byte

Z

Null-terminated string

. / @

Null fill or truncate to absolute/relative position

The size of an integer, as used by i and I, depends on the system architecture. Nybbles, bytes, shorts, longs, and quads are always exactly 4, 8, 16, 32, and 64 bits respectively. Characters s, S, l, and L may be followed by a ! to signify native shorts and longs instead. x and 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 [ and ], that will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required