in reply to Re^2: signed and unsigned templates in pack/unpack
in thread signed and unsigned templates in pack/unpack

You're packing a negative number with an unsigned template 'N', which means it will be treated as a large positive value. And when you unpack it, it will return that large positive value.

The solution is don't use an unsigned template for packing numbers than can be negative. Use a signed template:

$p = pack 'j', -3544;; print unpack 'j', $p;; -3544

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^4: signed and unsigned templates in pack/unpack
by posti (Novice) on Mar 02, 2010 at 13:53 UTC
    I see... Thanks a lot :-)