First of all, thank you very much for all your responses !

As jbert pointed out in his reply this seems to be either a bug in PerlIO itself or an erroneous (or at least misleading) documentation.

So my conclusion is:

To open() a file containing binary data in a portable manner without loosing buffering use the sequence

open(my $fh, '<', $filename); binmode($fh);

and avoid

open(my $fh, '<:raw', $filename)

how tempting it may look at first.


Some additional comments to my original post:

The "short version" of my question should have probably better been written as:

How do I portably and correctly open() a binary file without loosing buffering ?

I think the fact that the stream is unbuffered when specifying (only) the ":raw" layer in open() is quite important.

Also: My concern was not which layers are actually resulting from these two methods, but rather that they give different results on the same machine. I should have made that clearer.—Sorry !

Thanks to all your tests we know now that the behavior (be it a bug or not) is at least consistent across platforms and (some) Perl versions.

I'm also aware that UNIX treats binary data natively, so there is no need to call binmode() at all. So if you will my question was rather academic than having a real coding problem. (I hope that I didn't misuse this forum, though.)

Finally, my apologies for my possibly bad (or weird ?) English—it's not my native language.


In reply to Re: Using ":raw" layer in open() vs. calling binmode() by Anonymous Monk
in thread Using ":raw" layer in open() vs. calling binmode() 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.