Quoth [email protected] (Peter Pentchev):
> On Tue, Apr 21, 2009 at 10:24:10AM +0100, Paul LeoNerd Evans wrote:
> > I find lately I've been doing a lot of binary protocol work, taking
> > messages that live in TCP streams or files or similar, and doing lots of
> > pack()/unpack() on them.
> [snip]
> > 
> > Is there some neater way to do this? Can I either:
> > 
> >  a: Get unpack() to consume bytes from the LVALUE
> > 
> >  b: Ask unpack() how much it ate in a generic fashion?
> 
> Brief answer:
> - it's possible by patching the Perl source, see the last paragraph
>   for an explanation about a possible patch;
> - it could be done as an external module that must be kept in sync
>   with Perl's pp_pack.c.

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

Ben

Reply via email to