summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorPeter Dintelmann <Peter.Dintelmann@Dresdner-Bank.com>2006-05-05 15:20:24 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-05-12 16:55:36 +0000
commit54f961c9c7fe5166a70653b44c67c26122bfc1fd (patch)
tree8662fd94291cffe5fd157853519cdfa489197c3e /pod
parent64844641e1be28fdf8b7bba9436537339624f40b (diff)
downloadperl-54f961c9c7fe5166a70653b44c67c26122bfc1fd.tar.gz
AW: question on "len item/string item" with unpack()
From: "Dintelmann, Peter" <Peter.Dintelmann@Dresdner-Bank.com> Message-ID: <E9A2605289D8D7468B1A21EC24E59D2104979424@naimucx5.muc.allianz> p4raw-id: //depot/perl@28181
Diffstat (limited to 'pod')
-rw-r--r--pod/perlfunc.pod27
1 files changed, 15 insertions, 12 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 99291d49d2..73cde05efe 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 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>.