Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

unpack

Extracts values from a binary string according to a template.

The inverse of pack: takes a TEMPLATE and a binary STRING (or $_ if omitted) and returns a list of values extracted according to the template format characters. The template syntax is the same as for pack, including group syntax (...)N, repeat counts, and *.

String data is decoded using Latin-1 encoding (each byte maps 1:1 to a char code point), which correctly round-trips with pack’s output. The U format uses character offsets instead of byte offsets.

Synopsis

my @vals = unpack("A10", $data);
my ($long, $short, $str) = unpack("NnA*", $packet);
my @chars = unpack("C*", $bytes);
my @vals = unpack("A5", $_);   # $_ when string omitted

See Also

pack, vec, ord