From: Peter Dintelmann Date: Fri, 5 May 2006 13:20:24 +0000 (+0200) Subject: AW: question on "len item/string item" with unpack() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54f961c9c7fe5166a70653b44c67c26122bfc1fd;p=p5sagit%2Fp5-mst-13.2.git AW: question on "len item/string item" with unpack() From: "Dintelmann, Peter" Message-ID: p4raw-id: //depot/perl@28181 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 99291d4..73cde05 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -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 ICI. -The I can be any C template letter, and describes -how the length value is packed. The ones likely to be of most use are -integer-packing ones like C (for Java strings), C (for ASN.1 or -SNMP) and C (for Sun XDR). +For C you write ICI and the +I describes how the length value is packed. The ones likely +to be of most use are integer-packing ones like C (for Java strings), +C (for ASN.1 or SNMP) and C (for Sun XDR). For C, the I 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. If it has no repeat count or uses a '*', the number -of available items is used. For C the repeat count is always obtained -by decoding the packed item count, and the I must not have a -repeat count. +of available items is used. + +For C an internal stack of integer arguments unpacked so far is +used. You write CI and the repeat count is obtained by +popping off the last element from the stack. The I must not +have a repeat count. If the I refers to a string type (C<"A">, C<"a"> or C<"Z">), the I 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 is not returned explicitly from C.