The offset parameter refers to where you want Perl to place your data in the buffer, not the offset into the file. The docs say that it will zero pad the buffer if you specify a starting point that is different from 0 and the string has no characters in it already. See read and sysread. That is why you are seeing all those nulls.

To control the position within the file one needs to use seek, but that's only when one is going back and forth within a file. For the purposes of a simple sequential read, Perl keeps track of the position pointer all on its own and increments it after each read.

The offset parameter is normally used when you want to append data to a string or have a pipe where you want to make sure that you don't overwrite outgoing data at the front of the string with incoming data placed at the end.


In reply to Re: Reading binary file byte by byte by ELISHEVA
in thread Reading binary file byte by byte 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.