You probably want to use "\015\012" for CR/LF since the values of \r and \n vary from system to system

Bleh. I prefer to not let the mistakes of a single platform sway me away from previous good practices in writing portable code. The only platform where "\r" and "\n" caused any concern was old Macs. There are a lot more non-ASCII platforms where hard-coding magic numbers would cause problems. Granted, there was a period where running into what is now an "old" Mac Perl was much, much more likely than running into a non-ASCII Perl (at least for most people). It is a bit sad, however, that this visibility caused so many people to just overlook the long-standing realization that hard-coded magic numbers are a bad practice, including enshrining the encouragement of such bad practices in perlport (and some people who are still convinced that these hard-coded magic numbers are actually a "good practice").

But I've never run into an old Mac Perl and I strongly object to hard-coding such magic numbers so I find "\r" and "\n" much preferable. When writing code for public consumption, I might provide an abstraction that specifically detects old Macs. But the complexity of such an abstraction just isn't justified for me most of the time.

- tye        


In reply to Re^2: question about "split" function (magic numbers) by tye
in thread question about "split" function by rimvydazas

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.