Maybe your problem is just that a 32-bit signed integer cannot hold the value 3759263696 (too large).  In other words, if you use a signed int as in

my $hex = "d0cf11e0a1b11ae1000000000000000001000000feffffff00000000370 +00000ffffffff"; my $bin = pack "H*", $hex; for my $val (unpack "l<*", $bin ) { # last if $val == -1; print "val=$val\n"; }

you'd get

val=-535703600 val=-518344287 val=0 val=0 val=1 val=-2 val=0 val=55 val=-1

while, if you use an unsigned int (i.e. "L<*" in unpack), you'd get

val=3759263696 val=3776623009 val=0 val=0 val=1 val=4294967294 val=0 val=55 val=4294967295

but then you can no longer test for -1 as the stop condition...

Update: added "<" modifier (Perl 5.10) to the unpack templates (=force little endian), so the sample code would also run correctly on big-endian machines (note that for "L<" you could also say "V", but there's no respective equivalent of (signed) "l<")


In reply to Re: To 'pack' or 'unpack' that is the question by almut
in thread To 'pack' or 'unpack' that is the question by Wiggins

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.