Perl: the Markov chain saw | |
PerlMonks |
Re^11: Bit handling in Perlby BrowserUk (Patriarch) |
on Oct 27, 2014 at 14:54 UTC ( [id://1105161]=note: print w/replies, xml ) | Need Help?? |
Your problem is that you are mixing binary and text operations on the same file. When you are writing your records out, you are adding a "\n" at the end, and when you are reading them back you are relying upon readline to read back the appropriate number of characters by reading until it sees this newline. The problem comes when one of your binary records contains a data byte that happens to look like an LF character (0x0a; decimal 10). So, for example, in the third record of your sample, the 56th set of 8 1s&0s looks like this: 0,1,0,1,0,0,0,0, which when packed using the 'b*' template, gets translated in a byte value of 0x0a. Then, when you read the binary record back using readline (aka. <C>), perl sees that byte value as the end of the record, hence everything after that is wrong. The answer is (as hinted at in my first reply to you above) is to not use text operations (newline record separators and readline) on your binary files. Instead, when reading your binary files, you should use read and the exact number of bytes to read each record. Study the documentation for read. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|