Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: \r\n vs \012\015 (tye)

by tye (Sage)
on Aug 11, 2003 at 07:14 UTC ( #282772=note: print w/replies, xml ) Need Help??

in reply to \r\n vs \012\015, was Re(3) An introduction to POE
in thread An introduction to POE

Even when it comes to network protocols, "\r" and "\n" can be a better choice than "\012\015". In fact, the only reason this "\012\015" has become popular is the old Macintosh! If it weren't for that, then there would be no case where "\012\015" was a better choice.

Consider running Perl on an EBCDIC system (yes, there are such ports of Perl) trying to talk SMTP to send mail. You need to say "HELO\n" but try to be "portable" and say "HELO\012". You think the SMTP server you are talking to is going recognize "HELO" in EBCDIC?? Of course not. Which means that on an EBCDIC system talking over some socket emulation, you are going to be going through a EBCDIC/ASCII converting gateway and if you send "\012" through that from the EBCDIC side, it isn't going to reach the other side as "\n". You want "HELO\n".

It is sad that the old Mac mistakes have so confused people about what is portable code. "\012\015" is portable to the old Mac but is very specific to the near-ASCII nature of old Macs. Using such without first testing whether you are on a system where it works just indicates that you don't care about alternate character encodings. ASCII has become so popular that you can probably justify this sometimes.

But I find it silly that people proclaim how this makes their code more portable. It is just an old Mac thing. I'm not sure what non-ASCII environments Perl will end up running on; probably not very many. But hard-coding magic numbers is just not the way to go.

See Re^4: Line Feeds (rumor control) for if you want more on this. (:

                - tye

Replies are listed 'Best First'.
Re^2: \r\n vs \012\015 (tye)
by Anonymous Monk on Jan 13, 2010 at 05:32 UTC
    Actually if you want it to work across platforms you need to match (\r?\n|\015?\012)

      Either you didn't read the parent, or you disagree without explaining your disagreement. Neither case makes for a compelling and credible post.

      Please explain rather than making uncorroborated statements. For example, what platform would be served by /\r?\n|\015?\012/ but not by /\r?\n/?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://282772]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2020-09-29 14:20 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (146 votes). Check out past polls.