develooper Front page | perl.perl5.porters | Postings from May 2004

Group modifiers in (un)pack templates

Thread Next
Marcus Holland-Moritz
May 3, 2004 11:02
Group modifiers in (un)pack templates
Message ID:
I just thought that instead of having to write:

  $foo = pack "s<l<L<2Q<I<f<3"

it would be cool to be able to write:

  $foo = pack "(slL2QIf3)<"

Of course, it would then also be possible to write:

  $foo = pack "(sx![L]L2C4S/a(sl)3)>", @data;
  $foo = pack "(lL)>3(sS)<2", @data;

instead of:

  $foo = pack "s>x![L]L>2C4S>/a(s>l>)3", @data;
  $foo = pack "(l>L>)3(s<S<)2", @data;

This is especially useful when (un)packing large structures
of a certain byte-order.

I'll commit the attached patch - which implements the above and
adds docs and tests for it - tomorrow if I don't hear that this
is a bad idea.


BOFH Excuse #164:

root rot

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About