Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by joemaniaci (Sexton)
on Jul 23, 2012 at 22:27 UTC ( [id://983246]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^3: Missing byte using unpack, pack, read(in terms of bytes)
by RichardK (Parson) on Jul 23, 2012 at 22:46 UTC

    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://983246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found