Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
So the structure is:$data = '00010003206162'; $kategory = hex(substr($data,0,4)); $length = hex(substr($data,4,4)); $contents = pack('H'.$length*2, substr($data, 8, length($data)));
Now this code has to be really fast and I am sure it can be optimized. Since pack/unpack are very fast I hope that it is possible to do it along these lines (not working):
It should somehow go with help of '/' I found in the pack manpage but must admit that I didn't understand it and have no idea how the given examples work.my ($kat, $contents) = pack("h4 h4/H*", $data);
As an additional complication sometimes the size isn't given directly but has to be subtracted from 65536, e.g. a value of 'fff5' means 65536 - 65525 = 11 as the size. But even if this esoteric counting can not be directly done it would help a lot if I could improve at least the more simple case above.
Any idea how this is best done?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pack with count in the data
by ikegami (Patriarch) on Sep 29, 2008 at 13:27 UTC | |
|
Re: pack with count in the data
by Anonymous Monk on Sep 29, 2008 at 13:13 UTC | |
|
Re: pack with count in the data
by AnomalousMonk (Archbishop) on Sep 29, 2008 at 18:26 UTC | |
|
Re: pack with count in the data
by Anonymous Monk on Sep 30, 2008 at 05:33 UTC | |
by AnomalousMonk (Archbishop) on Oct 02, 2008 at 16:41 UTC |