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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |