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 be used as a repeat count; an asterisk (*) specifies all remaining arguments. A template between [ and ] is a repeat count equal to the length of the packed template. < (little-endian) and > (big-endian) can be used to force a specific byte order on a character or group.

Starting the template with U0 forces the result to be Unicode UTF-8, C0 forces bytes. Default is UTF-8.

If a format is preceded with %n, unpack returns an n-bit checksum instead. n defaults to 16.

Whitespace may be included in the template for readability, and a # character may be used to introduce comments.

A special case is a numeric character code followed by a slash and a string character code, e.g., C/a. Here the numeric value determines the length of the string item.

q and Q are only available if Perl has been built with 64-bit support. D is only available if Perl has been built to support long doubles.

perlpacktut.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset