This code works and will probably be somewhat faster than the code in the OP, but will certainly be slower than ikegami's suggestion, could it be used.
You might try "\@$offset" in place of the "x$offset"; it might give you a slight speed improvement, but I doubt it. (The backslash escape before the '@' is needed to prevent interpolation as an array in the double-quoted string of the unpack template.)C:\@Work\Perl\monks\714341>perl -wMstrict -le "print qq(\noutput:); for (@ARGV) { my $data = pack( 'H*', $_); my $offset = 0; while ($offset < length $data) { my ($kategory, $len) = unpack(qq{x$offset n n}, $data); $len = 65536 - $len if $len > 32767; my $contents = unpack(qq(x$offset x4 A$len), $data); $offset += 4 + $len; printf(qq(%04X, `%s' \n), $kategory, $contents); } print '------'; } " 0001fffd206162 0002000441424344 0001fffd20616200020004414243440005fffc454443 output: 0001, ` ab' ------ 0002, `ABCD' ------ 0001, ` ab' 0002, `ABCD' 0005, `EDC' ------
In reply to Re: pack with count in the data
by AnomalousMonk
in thread pack with count in the data
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |