# OS-Specific "\\n" Interpolation?

**URL:** <https://www.ruby-forum.com/t/os-specific-n-interpolation/80902>\
**Category:** Ruby\
**Created:** [January 1, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/os-specific-n-interpolation/80902 "2007-01-01T19:21:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [January 1, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/os-specific-n-interpolation/80902/1 "2007-01-01T19:21:47Z")

</div>

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/watch-those-newlines-ruby-no-different.html](http://rob.muhlestein.net/2007/01/watch-those-newlines-ruby-no-different.html)

---

<div class="post-metadata">

**Author:** ![coldtone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@coldtone](https://www.ruby-forum.com/u/coldtone)\
**Post date:** [January 1, 2007, 7:45pm UTC](https://www.ruby-forum.com/t/os-specific-n-interpolation/80902/2 "2007-01-01T19:45:52Z")

</div>

On Jan 1, 2007, at 7:20 PM, Rob M. wrote:

> 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

[\*] [Radar – O’Reilly](http://www.onlamp.com/pub/a/onlamp/2006/08/17/understanding-)  
newlines.html
