in reply to Problems Getting the Template Correct when Using unpack()
When unpacking data that contains a length record followed by data of that length, the / template character helps, although in this case it makes it a two-stage process:
my ($data,$taillen) = unpack 'C/aC', $inbuf; my @recs = (length($data), unpack('C7a6A*',$data), $taillen);
where as far as I can tell @recs is the same as your ($event_len, $year, ..., $tail_len). Also, TIMTOWTDI, the following return the same @recs, although I think these are a bit more ugly than the above:
# "X" means "back up one byte" my @recs = unpack 'C8a6A*XC', $inbuf; chop $recs[-2]; # remove final "tail_len" C from the string # - or - my @recs = $inbuf=~m{\A (.) (.)(.)(.)(.)(.)(.)(.) (.{6}) (.*) (\1) \z}msxaa or die "didn't match"; $_=ord for @recs[0..7,10];
|
|---|