I wanted to prevent it "falling back" into character mode and *always* return byte offsets.

By using bytes, you do exactly the opposite.

require bytes; $x = "\xC9\xCA\xCB\xCC"; utf8::downgrade($x); print(substr($x,1,1) eq "\xCA" ?1:0,"\n"); # 1 utf8::upgrade($x); print(substr($x,1,1) eq "\xCA" ?1:0,"\n"); # 1 utf8::downgrade($x); print(bytes::substr($x,1,1) eq "\xCA" ?1:0,"\n"); # 1 utf8::upgrade($x); print(bytes::substr($x,1,1) eq "\xCA" ?1:0,"\n"); # 0

bytes gives access to the internal storage format of the string. It has nothing to do with whether the string only contains bytes or not.

bytes::substr will probably do what you want. substr definitely will.

Further I thought binmode() is more a Win32 thing and as my code won't ever hit the MS world, I seldomly use it.

Prevents CRLF translations when the :crlf layer is used. Normally just on Windows.
Removes :encoding layers to prevent decoding. Shouldn't be there, but you're the one who's worried.

Just for completeness, my former code updated:

I don't know why you're asking for help (or why I'm giving it) if you sticking with that complex, buggy code when the simpler solution even does error checking.

Despite prompting, you never indicated whether it matters where you leave the file pointer when you're done. Does it?


In reply to Re^4: Advice needed on chunked read + byte-range logic by ikegami
in thread Advice needed on chunked read + byte-range logic by isync

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.