David --- Senior Programmer Analyst --- Wgo Wagner wrote: > I have a number of files which I have transferred from another > system. I am trying to read the data, but running into a problem when > I hit what is a negative number (Each field is 4 characters in > length). > > Here is the unpack: > > @MyWorka = > unpack("a8Nsa6a10ssa52H8a4H8H8a136",$fb010dbuf); > > This is the closest I have been able to get the info. If the value is > positive, number is okay, but if negative, then just a huge number. > If you look at rcd#3 Bill, you will see what I mean. If i I enter > that value and use printf and hex ( another script ), I get the > negative number I expect. > > What am I missing?
Hi David. I assume you mean the 'N' field? This is an unsigned 32-bit big-endian value, so it will always be positive. You can try 'l' (small el) which is a signed 32-bit value, but depending on your platform architecture it may not process the bytes in the right order. If not, you can just twos-complement your positive number depending on the sign bit: sub correct_sign { ($_[0] ^= 0xFFFFFFFF) += 1 if $_[0] & 0x80000000; } Note that this modifies its parameter 'in place' and so must be called with a scalar variable as its parameter. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]