[% setvar title pack/unpack uncontrovercial enhancements %]
To see what is currently happening visit http://www.perl6.org/
pack/unpack uncontrovercial enhancements
Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu> Date: 16 September 2000 Mailing List: perl6-language-data@perl.org Number: 246 Version: 1 Status: Developing
This RFC proposes simple enhancements to templates of pack/unpack builtins. These enhancements do not change the spirit of how pack/unpack is used. The semantic is enhanced as much as possible under this constaint.
Additional changes to pack/unpack are listed in other proposals.
The following additional constructs are allowed in pack()/unpack() TEMPLATEs:
, and ;denotes the same as whitespace.
[4]denotes the same as 4, as in 'i[4] S[4]'.
[TEMPLATE]denotes the same as [$LEN]; here $LEN is the length taken by the data
described by the template: $LEN = length pack TEMPLATE, @something
(as far as it does not depend on @something, so A* is prohibited).
This multiplier makes sense for byte-oriented types only. For example,
the middle part of 'C[32] C[L8] C[64]' will extract the substring which
consists of 8 packed longs. Similarly, 'C[32] x[L8] C[64]' will skip
this substring.
x!LENskip to offset divisible by LEN. For example, 'x![L]' will align
to a long-compatible boundary.
Wa BER encoded double.
w!a BER encoded "length", in other words, an integer encoded as BER lengths are.
(TEMPLATE)a group. May take a repeatition count either as (Ns)33 or as N/(Ns).
TEMPLATE1//TEMLATE2On unpack(): TEMPLATE1 extracts a number. This number specifies the number
of following bytes which the TEMPLATE2 should be applied to. (The difference
with TEMPLATE1/(TEMLATE2) is that in the latter case the number extracted
by TEMPLATE1 is not the number of bytes, but the repetition count.)
During pack(), makes the opposite operation.
For example,
pack 'n//(A[4] C*)', 'a', 9..14
does the same as
pack 'n A[4] C*', 10, 'a', 9..14
(this is especially useful with the grouping proposals introduced in a future RFC).
should work on 32-bit architectures too, using doubles instead (with a possible precision loss).
None.
Straightforward.
RFC142: Enhanced Pack/Unpack