summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorTon Hospel <perl5-porters@ton.iguana.be>2005-03-19 22:00:45 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-03-21 10:27:44 +0000
commit246f24af48839a0c276d6836d932a864d54afe73 (patch)
tree720117a6bd27a8543d8bf6424de90c20f7f758fb /pod
parentf1aa04aa98e25c473fc39871251cb722556cefa9 (diff)
downloadperl-246f24af48839a0c276d6836d932a864d54afe73.tar.gz
pack / for general types
Message-Id: <d1i7ed$62c$1@post.home.lunix> Allow "len/format" to work for any format type, not just strings. p4raw-id: //depot/perl@24052
Diffstat (limited to 'pod')
-rw-r--r--pod/perldiag.pod6
-rw-r--r--pod/perlfunc.pod32
2 files changed, 20 insertions, 18 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 3687d4192d..0f71025d35 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2336,12 +2336,6 @@ See L<perlfunc/open> for details.
(W syntax) Multidimensional arrays aren't written like C<$foo[1,2,3]>.
They're written like C<$foo[1][2][3]>, as in C.
-=item '/' must be followed by 'a*', 'A*' or 'Z*'
-
-(F) You had a pack template indicating a counted-length string,
-Currently the only things that can have their length counted are a*, A*
-or Z*. See L<perlfunc/pack>.
-
=item '/' must follow a numeric type in unpack
(F) You had an unpack template that contained a '/', but this did not
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 559e94b672..9785a250c6 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -3502,24 +3502,32 @@ so will result in a fatal error.
=item *
-The C</> template character allows packing and unpacking of strings where
-the packed structure contains a byte count followed by the string itself.
-You write I<length-item>C</>I<string-item>.
+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>, the I<string-item> must, at present, be C<"A*">, C<"a*"> or
-C<"Z*">. For C<unpack> the length of the string is obtained from the
-I<length-item>, but if you put in the '*' it will be ignored. For all other
-codes, C<unpack> applies the length value to the next item, which must not
-have a repeat count.
-
- 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"
+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.
+
+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'
The I<length-item> is not returned explicitly from C<unpack>.