I very rarely touch the command line on Windows, I use Linux or Cygwin, but I thought I'd try unpacking from a filehandle wrapped in a do block. Create a file with some unsigned little-endian shorts:-

C:\Users\johngg>perl -Mstrict -Mwarnings -e "print pack q{(S<)*}, 8412 + .. 8421" > littleEndian

Check that the file has the content we expect (Windows is not my natural environment so I drop into Cygwin to use hexdump - is there an equivalent in Windows?):-

$ hexdump -C /cygdrive/c/Users/johngg/littleEndian 00000000 dc 20 dd 20 de 20 df 20 e0 20 e1 20 e2 20 e3 20 |. . . . . + . . . | 00000010 e4 20 e5 20 |. . | 00000014

Now unpack the content:-

C:\Users\johngg>perl -Mstrict -Mwarnings -E "say for unpack q{(S<)*}, +do { open my $fh, q{<:raw}, shift or die $!; <$fh> };" littleEndian 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421

Using read to pull fixed length records into a buffer for processing is the best way to go but I hope this little aside is of interest.

Cheers,

JohnGG


In reply to Re: Using unpack on Windows with external data by johngg
in thread Using unpack on Windows with external data by locinus

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.