well... In my understanding it's just unclear what is the behaviour when used with unpack().
If you look later in the pack manual you can read :

 $baz = pack('s.l', 12, 4, 34);
 # short 12, zero fill to position 4, long 34

this is exactly what stated in the manual, it null-fills up to absolute position (in that case it will fill 2 bytes with zero)
so if you hexdump $baz it will contain (assuming a big-endian system):
00 0c 00 00 00 00 00 22

(on a little endian it would be  0c 00 00 00 22 00 00 00)

It's kind-of a surprising behaviour the one experienced when used with unpack()... but perhaps I just don't understand what the documentation mean with 'truncate'.


Cheers,
Andrea.

On Apr 22, 2009, at 7:40 PM, Ben Morrow wrote:

Quoth leon...@leonerd.org.uk (Paul LeoNerd Evans):
-=-=-=-=-=-

On Wed, Apr 22, 2009 at 02:10:03AM +0100, Ben Morrow wrote:
What am I missing here? It appears to me unpacking "." gives the current
byte position in the string, which is what is needed.

~% perl -E'my $bin = pack "NN", 10, 12; say for unpack ".N.N.", $bin'
   0
   10
   4
   12
   8

Ah, youknow, that is exactly what I wanted :)

I had in fact looked up and down the docs for a format which would do
something like that, and didn't find it. Is that documented anywhere?

I've just sat and reread perldoc -f pack and perldoc -f unpack _again_
and still haven't spotted it.

It appears (see Peter's reply) that it is only implemented in 5.10.
5.10's perldoc -f pack includes

   .   Null fill or truncate to absolute position specified by value.

which (besides being rather terse) doesn't explicitly say that unpack
"." will do what it does.

Ben


Reply via email to