in reply to Perl binary file reading

If it's binary data, it might have a ^D, which indicates the end of a stream of data. That's on Linux .. and I think a ^Z is used for Windows. I'm not positive about either of those, but it's somewhere to start looking.

If this is a file of records, hopefully the records are of a fixed length. If not, that makes things a little more challenging.

Some code would be helpful -- there are many ways to solve this, but we can offer much more useful solutions if we know where you're starting from. PS And please use code tags around the code. :)

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Replies are listed 'Best First'.
Re^2: Perl binary file reading
by Marshall (Canon) on May 02, 2016 at 22:36 UTC
    If using a console text input stream, a ^D on Unix or a ^Z on Windows will indeed result in an EOF for the user program.

    With an HD file, there is no such a thing! Because all files are binary on the hard disk. The file system returns "end of file" to the function reading when all bytes (in the intrinsically binary file) on disk are consumed. The file system always calculates EOF based upon number of bytes in the file. There is no ^D or ^Z at the "end of the file". This is needed for a text input stream because there is no limit on the number of bytes (characters).

    Using read and a big buffer like 50 MB could be ok on a modern computer. Reading in smaller chunks is fine, but more complicated.

Re^2: Perl binary file reading
by afoken (Chancellor) on May 02, 2016 at 20:22 UTC
    If it's binary data, it might have a ^D, which indicates the end of a stream of data. That's on Linux .. and I think a ^Z is used for Windows.

    Should be no problem with binmode.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Right -- that was my point. If they're using readline, they're subject to the rules of reading text (break the chunks into lines, stop at the 'end of file'). If they're using read, then they'll just get chunks of the file up to the file size.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.