It's not really your unpacks that are messy.

But your unpacks could be improved by treating the records as follows the following format:

header body footer ------------ --------- ------ id body_size size path crc32

How I'd write it:

#!/usr/bin/perl use strict; use warnings; my $mem = pack('H*', '54424c004100001300000BAD2F62696E2F7465737432302E +64666C376F6B0F42000013000000042F62696E2F7465737430312E64666C376D6C0F4 +3000013000000042F62696E2F7465737430322E64666C376D6D0F4400001300000004 +2F62696E2F7465737430332E64666C376D6E0F45000013000000042F62696E2F74657 +37430342E64666C376D6F0F46000013000000042F62696E2F7465737430352E64666C +376D700F47000013000000042F62696E2F7465737430362E64666C376D710F4800001 +3000000042F62696E2F7465737430372E64666C376D720F49000013000000042F6269 +6E2F7465737430382E64666C376D730F4A000013000000042F62696E2F74657374303 +92E64666C376D740F4B000013000000042F62696E2F7465737431302E64666C376E6B +0F4C000013000000042F62696E2F7465737431312E64666C376E6C0F4D00001300000 +0042F62696E2F7465737431322E64666C376E6D0F4E000013000000042F62696E2F74 +65737431332E64666C376E6E0F4F000013000000042F62696E2F7465737431342E646 +66C376E6F0F50000013000000042F62696E2F7465737431352E64666C376E700F5100 +0013000000042F62696E2F7465737431362E64666C376E710F52000013000000042F6 +2696E2F7465737431372E64666C376E720F53000013000000042F62696E2F74657374 +31382E64666C376E730F54000013000000042F62696E2F7465737431392E64666C376 +E740F55000011000000042F6574632F74657374322E73683B0C08495600000D000000 +082F477053772E63686B1175D3BB'); (my $section, $mem) = unpack('Z* a*', $mem); print("$section\n"); print( ( "-" x length($section) ), "\n"); while (length($mem)) { (my $id, my $body, my $crc, $mem) = unpack('n n/a N a*', $mem); my ($size, $path) = unpack('N a*', $body); # Check CRC here. print("Load ID : $id\n"); print("Load Size : $size\n"); print("Load Path : $path\n"); print("\n"); }
TBL --- Load ID : 16640 Load Size : 2989 Load Path : /bin/test20.dfl Load ID : 16896 Load Size : 4 Load Path : /bin/test01.dfl Load ID : 17152 Load Size : 4 Load Path : /bin/test02.dfl ...

Update: Added enumeration at the top.


In reply to Re: Better unpack solution available by ikegami
in thread Better unpack solution available by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.