in reply to Re: Unpack()ing a stream
in thread Unpack()ing a stream

What on earth does '(a*/N)*' do? unpack seems to be trying to use it, but I can't work out what kind of input to supply?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Re: Unpack()ing a stream
by diotalevi (Canon) on May 24, 2004 at 18:38 UTC

    When given to pack() it consumes a list of strings and returns a single string where every string is now prefixed with the length, encoded in a big-endian 32 bit value. Its fantastic for serializing a bunch of strings. Do note - I wrote the format backwards so the "N" comes before the "A*". pack will tell you this as well so you can't make the mistake and let it just get away from you.

    pack '(N/a*)*', list of strings; $foo = pack '(N/a*)*', "A", "BB", "CCC", "DDDD"; $foo eq ( "\0\0\0\1A" . "\0\0\0\2BB" . "\0\0\0\3CCC" . "\0\0\0\4DDDD" +);

      Okay. I'm aware of the 'N/a*' ('c/a*', 's/a*' etc.) formats.

      It was the reversal that confused me, combined with that when I tried it with unpack, it doesn't report an error.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail