Riddle me this my Monkish friends.

I am currently trying to write a perl script to parse a binary file. No problem using unpack(still trying to gernerate all the templates, but not the issue at hand.)

The file is made of of records, each record is made up of a header and data portion. Within the header the length of the data portion is identified. No problem see below

The program reads the header, calculates the the size of the remaining data then reads that information

The problem that I run into is that the system seems to read twice the size I am requesting. i.e. My first read is bytes 0-20, assuming the data portion is 100 bytes it should read 21-120. But instead it reads 0-20, skips 21-40, reads 41-140, skips 141-240, read the next header.

Any Ideas on this. I have tried both read and sysread and I get slightly different results but neither work properly.

System:
Win NT
ActiveState Perl

Thanks

In reply to Reading Binary file confusion by Anonymous Monk

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.