in reply to Pack number to unsigned short

and many error/warning messages

You didn't feel it worthwhile to post (or, apparently, to ponder) | to ponder any of these error/warning messages, but it's sometimes useful to let Perl help you.

c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $count = 17767; my $c16 = pack('S', $count); printf(qq{Count = dec %d, hex 0x%04x, c16 = 0x%04x \n}, $count, $count, $c16); " Argument "gE" isn't numeric in printf at -e line 1. Count = dec 17767, hex 0x4567, c16 = 0x0000
The Argument "gE" isn't numeric in printf at ... warning I'm assuming you got should have been a clue that there was a disjunction between the thing you were trying to print as a number and the numeric nature of the thing itself. I'm assuming you already used them, but, in any event, please see warnings and strict.

It's also possible to gain insight into the structure of a packed string (once you realize it is a string) with a quick, roll-your-own hex dumper:

c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $count = 17767; printf qq{%d decimal, %x hex \n}, $count, $count; ;; for my $template (qw(S n v N V)) { printf qq{template '$template': }, $template; my $p = pack $template, $count; printf '%02x ', $_ for unpack 'C*', $p; print ''; } " 17767 decimal, 4567 hex template 'S': 67 45 template 'n': 45 67 template 'v': 67 45 template 'N': 00 00 45 67 template 'V': 67 45 00 00
(I'm sure there are better string hex dumpers avaliable on CPAN.)

Update: I notice now that you did, in fact, post many of the warning messages, so I've altered my reply accordingly.


Give a man a fish:  <%-{-{-{-<