For those of you smug about always being on Unix, it is now recommended to use binmode even on Unix to avoid unwanted Unicode semantics.
  1. Mac OS is sane too so you should address smug users from both camps.

  2. Saying "it is recommended" doesn't mean much without the source of the recommendation.

    Though the ability to set layers for filehandles has been grafted onto binmode(), they can also be set via the open pragma and overridden with the three argument form of open(). If I were making my own recommendation, I'd suggest these over binmode() as being clearer and more natural.

  3. You're oversimplifying.

    IO layers are, to be fair, a separate issue from that which started this discussion. The use of layers is a powerful abstraction which provides a lot of functionality over and above the ability to fix braindead line terminations and EOF markers.

    Furthermore, for the most part, perl tries pretty hard to do the Right Thing™ (on sane platforms) regardless of whether layers are specified. Backward compatibility is, as always, a high priority so the default behavior is for perl to behave as it always has. My understanding is that the exception occurs when one has specified their preference for Unicode semantics via one of the locale environment variables, in which case, presumably, you know what you are doing.

To the best of my knowledge, using binmode on binary files is recommended regardless of platform but only for portability reasons. In my case, most of what I write is specific to unix anyway because it supports systems that are themselves tightly coupled to unix. Usually, my only portability concern is that my code will build and run unaltered on Irix, Solaris, various BSDs, and Linux. Unsurprisingly, I regularly ignore binmode() as being wholly superfluous and I'll continue to do so until I hear a good reason not to.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: binmode for @ARGV by sauoq
in thread binmode for @ARGV by BrowserUk

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.