in reply to Perl 6 wish list: pack/unpack meta-feature

You could, of course, just make a better unpack and turn it into a module. I would think that adding user defined types would slow down unpack, which would make this kind of move very unpopular with people who's business revolves around packing/unpacking a lot of binary data.

I have to admit that at times I'm also a little frustrated by the limitations of pack, especially when you don't have the sort of "stream" methods that you can get, say, in C++, where you can really go to town.

Applying the TMTOWTDI principle, this would mean that the "traditional" way would be fast, but limited, and the "new" way, which is extensible, would be "better" at the expense of speed.

The function names here are, of course, just for the example:
use Super::Unpack; my ($foo,$lola,$glarb) = super_unpack ('int int MyType'); my ($foo,$lola,$glarb) = super_unpack (qw [ int int MyType]); my ($foo,$lola,$glarb) = super_unpack (@spec); my ($foo,$lola,$glarb) = super_unpack ('network unsigned int','short', +'MyType');
With a few pre-defined "internal" types, such as 'int', 'long', and 'unsigned short', you could go places really quickly.

Then this new module could be a Perl6 standard-issue thing, assuming people were open to this sort of idea.

Replies are listed 'Best First'.
Re: Re: Perl 6 wish list: pack/unpack meta-feature
by John M. Dlugosz (Monsignor) on Jul 26, 2001 at 08:42 UTC
    There are several proposals for improvements to the traditional unpack, and a significant one for a new design. You ought to read that RFC.

    My point is that if it's moved out of the core, why be limited to just one "official" one?

    Also, I don't think adding user-defined types to traditional unpack would slow it down one iota. Consider: internally it switches on the letter and jumps to suitable code for that. Adding more entries for more letters will have no effect on the stuff that's already there.

    —John