packs data into a string of bytes. each format character corresponds to one or more arguments.
$ pack('format', @array)packs data into a string of bytes. each format character corresponds to one or more array elements.
'format' - a string describing the number of values to expect and their types.
$x, ... - an arbitrary piece of data. the pack format describes how many pieces of data to expect and what type to pack them into.
@array - an array full of arbitrary pieces of data used by this function.
a scalar string containing byte representations of the arguments as specified by the format string.
# pack a long into an unsigned integer representation $bytes = pack("I", 3232235777L); # unpack bytes into 4 unsigned bytes @bytes = unpack("B4", $bytes); # print them out :) println(@bytes); # for giggles... go in reverse $bytes = pack("B4", reverse(@bytes)); $value = unpack("I", $bytes); # print out the value println($value);
@(192, 168, 1, 1) @(3232235777L)