in reply to Looping through a binary file

There's a stray $index variable on line 25, but the program basically works for me. To reproduce your error, also provide the input data.