In a recent thread, I was thinking about (and was probably not the first to do so) the issue of \n being conveniently interpreted in several ways depending on the platform perl runs on (i.e. LF on Unices, CR on MacOS, CR+LF on DOS/Windows...). Convenient when dealing with text files but just plain annoying when you want to deal with some network protocol that demand a CR+LF as a line delimiter although they deal mostly with text (like, e.g., SMTP).

Then tye accurately pointed out that specifying \015\012 wouldn't prevent perl from inserting another \015 when running on Windows.

So what shall we do?

  1. use Socket qw( :crlf ): but this does nothing but provide constants for \015, \012 and \015\012.
  2. use the code from CGI.pm that tries its best to determine what architecture it's running on and sets variables accordingly. Should this particuliar bit of code be made into a module of its own?
  3. Write in binmode and use the aforementionned constants. Then what are the implications of this? Does binmode only affect the way \n is interpreted?

Thanks for your time and enlightened remarks.

--bwana147


In reply to binmode, CR, LF by bwana147

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.