in reply to Re: Write 2 uint16_t numbers to file in Perl
in thread Write 2 uint16_t numbers to file in Perl

seek($fh, 2*16, 0); # Double up 'cause 'seek' wants bytes not short ints

Rather than having numeric literals running around all over the place, it's possible to capture pack-spec widths:

c:\@Work\Perl>perl -wMstrict -le "use constant SIZEOF_S => length pack 'x[S]'; print SIZEOF_S; ;; use constant SIZEOF_WHATEVER => length pack 'x[NSc]'; print SIZEOF_WHATEVER; " 2 7
(It may be perfectly safe to use the shorter  'S' etc., rather than the more verbose  'x[S]' form in the pack statement, but I have the sneaking suspicion that a pitfall may lurk there... can't remember it atm.)


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

Replies are listed 'Best First'.
Re^3: Write 2 uint16_t numbers to file in Perl
by Anonymous Monk on Jan 05, 2016 at 21:06 UTC

    The OP needs to match his pack/unpack template to the data, not the other way around. If anything, he might want to consider 'n' vs 'v' vs 'S'.