Pack and Unpack


pack() and unpack() provide a set of powerful tools for reading, creating, and manipulating binary data.

pack() and unpack() are a lot like tools for working on your car. You don't need them to drive the car, but as soon as you want to really monkey around under the hood, you can't live without them. These functions let you directly manipulate binary data. By combining them with the file functions, you can write applications that can read and write almost any binary file format. See the examples in unpack() on reading dbf files for a small example of the things that can be accomplished with these functions.

Camel wrestlers will recognize these functions - they were borrowed from Perl and behave in almost the same way. There are a few minor differences: Not all of the format codes are supported, the format strings can only have spaces in a few specific places, and unpack() returns the parsed data in an associative array.

Table of Contents

pack
unpack