in reply to To 'pack' or 'unpack' that is the question
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<")
|
|---|