http://qs321.pair.com?node_id=282618


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.
--
Mike

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/?