AW: question on "len item/string item" with unpack()
authorPeter Dintelmann <Peter.Dintelmann@Dresdner-Bank.com>
Fri, 5 May 2006 13:20:24 +0000 (15:20 +0200)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 12 May 2006 16:55:36 +0000 (16:55 +0000)
From: "Dintelmann, Peter" <Peter.Dintelmann@Dresdner-Bank.com>
Message-ID: <E9A2605289D8D7468B1A21EC24E59D2104979424@naimucx5.muc.allianz>

p4raw-id: //depot/perl@28181

pod/perlfunc.pod

index 99291d4..73cde05 100644 (file)
@@ -3727,29 +3727,32 @@ so will result in a fatal error.
 The C</> template character allows packing and unpacking of a sequence of
 items where the packed structure contains a packed item count followed by 
 the packed items themselves.
-You write I<length-item>C</>I<sequence-item>.
 
-The I<length-item> can be any C<pack> template letter, and describes
-how the length value is packed.  The ones likely to be of most use are
-integer-packing ones like C<n> (for Java strings), C<w> (for ASN.1 or
-SNMP) and C<N> (for Sun XDR).
+For C<pack> you write I<length-item>C</>I<sequence-item> and the
+I<length-item> describes how the length value is packed. The ones likely
+to be of most use are integer-packing ones like C<n> (for Java strings),
+C<w> (for ASN.1 or SNMP) and C<N> (for Sun XDR).
 
 For C<pack>, the I<sequence-item> may have a repeat count, in which case
 the minimum of that and the number of available items is used as argument
 for the I<length-item>. If it has no repeat count or uses a '*', the number
-of available items is used. For C<unpack> the repeat count is always obtained
-by decoding the packed item count, and the I<sequence-item> must not have a
-repeat count.
+of available items is used.
+
+For C<unpack> an internal stack of integer arguments unpacked so far is
+used. You write C</>I<sequence-item> and the repeat count is obtained by
+popping off the last element from the stack. The I<sequence-item> must not
+have a repeat count.
 
 If the I<sequence-item> refers to a string type (C<"A">, C<"a"> or C<"Z">),
 the I<length-item> is a string length, not a number of strings. If there is
 an explicit repeat count for pack, the packed string will be adjusted to that
 given length.
 
-    unpack 'W/a', "\04Gurusamy";        gives ('Guru')
-    unpack 'a3/A* A*', '007 Bond  J ';  gives (' Bond', 'J')
-    pack 'n/a* w/a','hello,','world';   gives "\000\006hello,\005world"
-    pack 'a/W2', ord('a') .. ord('z');  gives '2ab'
+    unpack 'W/a', "\04Gurusamy";            gives ('Guru')
+    unpack 'a3/A A*', '007 Bond  J ';       gives (' Bond', 'J')
+    unpack 'a3 x2 /A A*', '007: Bond, J.';  gives ('Bond, J', '.')
+    pack 'n/a* w/a','hello,','world';       gives "\000\006hello,\005world"
+    pack 'a/W2', ord('a') .. ord('z');      gives '2ab'
 
 The I<length-item> is not returned explicitly from C<unpack>.