On Tue, Jun 12, 2001 at 12:02:21AM -0400, Adam Russell wrote:
>  So, ok. I now know how to get a CR in MacPerl. However, why does MacPerl
> convert \r to \n ?

Oh, I see, I thought you were asking how to protect a carriage return
character when FTPing a script from Unix to Mac.


The usual way to print a line of text is like this:

print "Hello, world!\n";

On Unix, that'll end the line with a linefeed, which is the Unix newline.
On a Mac, though, the newline character is a carriage return.  Instead of
making people change that code to:

print "Hello, world!\r";

to run under MacPerl, MacPerl swaps the meaning of "\n" and "\r".  "\n" is
a carriage return, and "\r" is a linefeed.

And on Windows, "\n" is magically converted to a carriage return followed
by a linefeed, which is the Windows newline.

So, whereever you go, "\n" does what you mean, yielding the local newline.


If you want an actual carriage return or linefeed, regardless of
platform, you should use octal or hex escapes instead.  For example:

print SOCKET "Hello, world!\015\012";


Ronald

Reply via email to