Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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

by RMGir (Prior)
on Aug 10, 2003 at 13:48 UTC ( #282618=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: An introduction to POE
in thread An introduction to POE

(We're getting pretty far off the topic of POE here...)

You are correct for network protocols. Of course, at that level it's important that the correct bytes are sent, if you're doing raw FTP or RSH, for instance.

But for terminal interactions, you have to have "the right thing" happen. And what does the right thing can be different from platform to platform. In those cases, I think \n and \r are the correct choices.

Even if you're accessing another system remotely, it's the terminal driver on that system that will make the decision how to translate local \n into the right thing on the wire.

  • Comment on \r\n vs \012\015, was Re(3) An introduction to POE

Replies are listed 'Best First'.
Re: \r\n vs \012\015 (tye)
by tye (Sage) on Aug 11, 2003 at 07:14 UTC

    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
      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://282618]
[erix]: I recognise the makings of a fine argument
[LanX]: lanx wonders ... how likely is it to talk >95% BS without intention?
[erix]: "gigantic amounts of data" is also not SQLite (imho)
talexb wonders why sqlite2 was deprecated in favour of sqlite3.
[erix]: looks like a fork, rather, no?
LanX /me /me
[erix]: /hehehe
[marto]: LanX yesterday I found out about Gish gallop tactic

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2017-07-28 15:33 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (431 votes). Check out past polls.