Your file needs to have a multiple of sizeof(int) bytes. It probably doesn't.
At a glance, I see three bugs:
@bufAry = unpack('I*', $buf); assumes the buffer contains a multiple of sizeof(int) bytes.
Similarly, your output loop always starts writing from the start of the buffer, even if those bytes have already been written. Why not just use print?
my @bufAry = []; places a reference to an anonymous array in the array. That makes no sense. Good thing you overwrite this before using @bufAry. Remove the incorrect and useless initialization.
Furthermore,
The lack of use strict; or equivalent is sad. ALWAYS use this.
There's also the useless undef($buf);. Actually, it's worse than useless. It forces the string buffer to be deallocated, only to have it re-allocated on the next time. This is a waste of CPU, and it can fragment your memory.
You're needlessly using global variables for your handles. Don't do that. Use lexical variables like you do everywhere else. We're not in the 1990s.
Avoid two-arg open. Again, we're not in the 1990s.
Finally, I also question if I is the right format, since it's not the same size on every machine. See Mini-Tutorial: Formats for Packing and Unpacking Numbers.
In reply to Re: binmode copy loses final byte
by ikegami
in thread binmode copy loses final byte
by aplonis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |