Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Missing byte using unpack, pack, read(in terms of bytes)

by Corion (Patriarch)
on Jul 23, 2012 at 22:10 UTC ( [id://983245]=note: print w/replies, xml ) Need Help??


in reply to Missing byte using unpack, pack, read(in terms of bytes)

You don't show how you open the file, and you don't tell us the platform you're using.

If you are on Windows, my guess is that you forgot to use binmode on the file, and newline translation is hitting you.

If that guess is wrong, then please show a short, self-contained program that reproduces the problem, and also tell us the version of Perl you're using.

  • Comment on Re: Missing byte using unpack, pack, read(in terms of bytes)

Replies are listed 'Best First'.
Re^2: Missing byte using unpack, pack, read(in terms of bytes)
by joemaniaci (Sexton) on Jul 23, 2012 at 22:27 UTC

    Windows 7 64-bit perl v5.12.3 I open the file using...

    open(IN, $nameoffile) or die "Can't open $!\n";

    I have not seen binmode so I am definitely not using that. I have my .pl file on a classified network not connected to the internet so I would have to retype the entire thing. I am almost positive it is not my code though since I can repeat the exact same time thousands of times before this issue pops up at some random point.

    EDIT: Looking at binmode, before I open the file, should it be...

    binmode STDIN, ":bytes"; open(IN, $nameoffile) or die "Can't open $!\n";

    Or should it be...

    binmode IN, ":bytes"; open(IN, $nameoffile) or die "Can't open $!\n";

    EDITEDIT: I just tried including binmode and the behavior didn't change whatsoever, unless both of my examples above are wrong. As far as I can tell these files contains a single massive block of hex data so I don't think I have to worry about any newlines.

      You need to call binmode after you open the file

      open(IN,'<','filename') or die "$!"; binmode IN;

        I owe you a six pack, in all that time researching pack and unpack and endian, I never came across binmode. You're a life saver.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://983245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found