in reply to Using ":raw" layer in open() vs. calling binmode()
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using ":raw" layer in open() vs. calling binmode()
by Anonymous Monk on Jun 15, 2007 at 09:37 UTC | |
by Anonymous Monk on Jun 15, 2007 at 14:10 UTC | |
by Anonymous Monk on Jun 15, 2007 at 15:41 UTC |