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:  <%-{-{-{-<


In reply to Re: Pack number to unsigned short by AnomalousMonk
in thread Pack number to unsigned short by BrianP

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.