[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

basic doubts on "\n"

Xavier Noria

7/16/2003 10:01:00 AM

I am trying to get the picture about how "\n" works in Ruby.

Since this is somewhat difficult to concrete in a single question I have
broken the issue in a few ones. Let's see how it works.

* Does "\n" play the role of logical newline? In a broad sense, if that
was the case portable line-oriented code would use "\n" as newline for
reading and writing through non-binmoded streams. (True in Perl, false
in Java.)

* Is "\n".length == 1 no matter the platfrom? (True in Perl, true in
Java.)

* Does "\n" == "\x0a" hold no matter the platform? (False in Perl, true
in Java.)

* Does "\n" get translated by the underlying I/O system back and forth
to native newlines in non-binmoded streams? (True in Perl, false in
Java.)

Thank you very much, and regards from warm Barcelona,

-- fxn


1 Answer

Robert Klemme

7/16/2003 11:34:00 AM

0


"Xavier Noria" <fxn@hashref.com> schrieb im Newsbeitrag
news:200307161202.31854.fxn@hashref.com...
> I am trying to get the picture about how "\n" works in Ruby.
>
> Since this is somewhat difficult to concrete in a single question I have
> broken the issue in a few ones. Let''s see how it works.
>
> * Does "\n" play the role of logical newline? In a broad sense, if that
> was the case portable line-oriented code would use "\n" as newline for
> reading and writing through non-binmoded streams. (True in Perl, false
> in Java.)

Yes. But you can change that either by setting $/ to something else or by
using IO#each or IO#each_line with a string used as record (i.e. line)
separator.

> * Is "\n".length == 1 no matter the platfrom? (True in Perl, true in
> Java.)

Yes.

> * Does "\n" == "\x0a" hold no matter the platform? (False in Perl, true
> in Java.)

I think so.

> * Does "\n" get translated by the underlying I/O system back and forth
> to native newlines in non-binmoded streams? (True in Perl, false in
> Java.)

I think so. On win platform i always receive lines with a single "\n" at
the end, although the OS uses "\r\n".

> Thank you very much, and regards from warm Barcelona,

Warm regards from warm Paderborn to warm Barcelona

robert