Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   OS-Specific "\n" Interpolation? (http://www.velocityreviews.com/forums/t836820-os-specific-n-interpolation.html)

Rob Muhlestein 01-01-2007 06:18 PM

OS-Specific "\n" Interpolation?
 
Coming from Perl and C I have come to expect "\n" to be translated
differently depending on OS--especially when doing sockets protocol
programming. Ruby *appears* to be subject to this same OS/clib
translation issue which is so often overlooked. Was hoping Ruby
shielded the average user from this. Has anyone else had any experience
confirming or denying this? I've written up the details in a blog post:

http://rob.muhlestein.net/2007/01/wa...different.html


Xavier Noria 01-01-2007 06:44 PM

Re: OS-Specific "\n" Interpolation?
 
On Jan 1, 2007, at 7:20 PM, Rob Muhlestein wrote:

> Coming from Perl and C I have come to expect "\n" to be translated
> differently depending on OS--especially when doing sockets protocol
> programming. Ruby *appears* to be subject to this same OS/clib
> translation issue which is so often overlooked. Was hoping Ruby
> shielded the average user from this. Has anyone else had any
> experience
> confirming or denying this? I've written up the details in a blog
> post:
>
> http://rob.muhlestein.net/2007/01/wa...lines-ruby-no-
> different.html


In Ruby "\n" is a string of lentght 1 in all systems, and it is equal
to "\012" in all platforms. This works as in Perl and other languages
that inherit from C the way newlines are handled[*], except it is
simpler because it does not have the MacPerl exception.

In these languages you write portable sockets programming by
binmodeing the socket and hard-coding "\015\012" or whatever.

As a side note, by default modern Perl performs newlines transaltion
on CRLF platforms via the custom PerlIO I/O layer, the C Ruby
interpreter delegates this to stdio.

-- fxn
[*] http://www.onlamp.com/pub/a/onlamp/2...understanding-
newlines.html





All times are GMT. The time now is 07:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.