develooper Front page | perl.perl5.porters | Postings from March 2000

templates in pack/unpack

Ilya Zakharevich
March 4, 2000 13:48
templates in pack/unpack
Message ID:
This is to remind people that embedded-template support for
pack/unpack operator was dropped to the floor by Sarathy without any

I recall that 't' and 'T' unpack specifiers would allow the unpack
template to be embedded into the packed string.  One of the most
important advantages is a possibility to unpack an arbitrary Perl
value from a string, without putting a lot of restrictions on the
format of the packed string.

The same expression

  @values = unpack 'T*', $packed;

would allow $packed to 

  *) contain word-aligned machine-format data;
  *) contain a C string (no embedded \0);
  *) contain an easily-human-readable representation of data

or satisfy many other useful restrictions.  All this flexibility is
due to flexibility of pack/unpack which used for serialization.
Moreover, existing serialization modules could be easily updated to
support formats readable by unpack 't'.

Additionally, symmetric functionality for pack() was provided which
provided one of the infinitely many possible ways to serialize data
for unpack 't'.

There were some initial objections due to misunderstanding of the
posted example: people thought that the examples of serialization I
initially posted for illustration were the *only* ways to serialize
data.  But IIRC, all the expressed doubts were addressed by future

Thank you for your attention,
Ilya Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About