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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.