I don't know that I can be of much help. I'll give some generic "checklist" advice:

I've implemented fixed size record code before with standard buffered read/write/seek. There are a couple of ways to go wrong.
1) Make sure that your "byte math" is right. You didn't say whether you are on Windows or not, but Windows uses CR,LF instead of just LF for \n (like Unix).
2)On most file systems you need to do an intervening seek or tell operation when switching from read to write (this can flush buffers amongst other things). The normal way is "seek (HANDLE,0,SEEK_CUR);". That seeks 0 bytes from current position and therefore is a logical "do nothing", but some things happen under the covers. It could be that this usually happens by accident, but occasionally it doesn't.
3) If you are going to use the unbuffered read/writes, use sysseek() instead of seek(). Of course don't mix buffered and unbuffered operations on the same file.
4)These fixed record length files normally should have every byte written in them unless you know that you are creating a "sparse file". It could possibly be that you have accidentally created a sparse file.

Other things: seek() does return a status of worked or didn't work. Normally seek() doesn't fail, but it might be interesting to see if that happens or not. An attempted seek to before beginning of file could cause some trouble. Also, it is possible to seek past the EOF. That is completely legal even on Win XP's NTFS. This is used to create "sparse" files, files that have gaps in them. This kind of file will report its size in ls or dir as the "theoretical max", but "du" in Unix will tell a different story. Maybe sometime you are seeking out there into "no man's land" and trying to read. That might produce some really strange results.

Of course it would be helpful it you could say that OS and Perl version that you are using. You can't post some 15MB data file here, but if you could come up with some short gizmo that generates some dummy data and is able to demonstrate the problem, that would be helpful. What you are trying to do should work with buffered I/O and normal seek().


In reply to Re: Buffered IO and un-intended slurping by Marshall
in thread Buffered IO and un-intended slurping by Wiggins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.