From: "Mark J. Reed" Date: 2003-07-16T23:07:51+09:00 Subject: Re: basic doubts on "\n" XN = "Xavier Noria" XN> I am trying to get the picture about how "\n" works in Ruby. Okay. XN> * Does "\n" play the role of logical newline? XN> * Does "\n" get translated by the underlying I/O system back and forth XN> to native newlines in non-binmoded streams? Yes. For example, in text-mode streams under Windows, outputting "\n" from Ruby results in "\r\n" being written, and "\r\n" becomes "\n" when read into Ruby. Under pre-X Mac OS, outputting "\n" from Ruby results in "\r" being written, and "\r" becomes "\n" when read into Ruby. XN> * Is "\n".length == 1 no matter the platform? XN> * Does "\n" == "\x0a" hold no matter the platform? Yes. Within the Ruby code, "\n" always represents a string of length 1 whose single character (which, at least through 1.8, means single byte) has the decimal value 10. The conversion to other strings happens only on input and output. XN> (False in Perl) Yes, but only because of MacPerl, in which "\n" represents chr(13) everywhere while "\r" represents chr(10) everywhere. This is one of several MacPerl design decisions that in retrospect may not have been the way to go, but with which we now seem to be stuck. :) -Mark