A little explanation of the changes, with some corrections:

C4 is the same as C C C C. It extracts 4 numbers.

$ perl -e'printf "0x%X\n", $_ for unpack "C4", "\x12\x34\x56\x78"' 0x12 0x34 0x56 0x78

But that's not what you want. You want to extract a single 32-bit unsigned integer in little-endian byte order.[1] After consulting Mini-Tutorial: Formats for Packing and Unpacking Numbers, we determine that we need L< or V for that.

$ perl -e'printf "0x%X\n", $_ for unpack "L<", "\x12\x34\x56\x78"' 0x78563412

So, what you want is

unpack( 'a4 C C Q< L< L< L< C', $ogg_head )

Note that this is only 27 bytes, not 28. The number of remaining bytes is indicated by that last field (the 27th byte), and may be a number other than one.

As hinted by the parent, Q is only available on builds of Perl with 64-bit integers (i.e. where perl -V:uvsize aka perl -Mv5.10 -MConfig -e'say $Config{uvsize}' prints 8 or more).


  1. The parent assumed big-endian order and thus used N. But the spec says little-endian byte order is used, which is repeated here.

In reply to Re^2: pack/unpack woes by ikegami
in thread pack/unpack woes by james289o9

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.