\r\n for EOL in windows?

I believe "\r\n" is a normal newline for windows "type" files.

Should the following work, then, seeing as $ is supposed to mean "end of
line"?

"abc\r\n" =~ /abc$/

=> nil

This works:

"abc\n" =~ /abc$/

=> 0

I'm guessing it shouldn't, actually, and current behavior is expected.
Thanks!
-roger-

···

--
Posted via http://www.ruby-forum.com/\.

I believe "\r\n" is a normal newline for windows "type" files.

Yes, but in a ruby program it's just "\n". ruby will take care of
converting from and to the platform specific newline when you read or
write. For instance, if you are using windows and write "\r\n" ruby
will convert the "\n" to "\r\n" giving you the output: "\r\r\n", which
is not what you want.

···

--
Posted via http://www.ruby-forum.com/\.

Only in disk. When you work in text mode the I/O layer transforms from native to \n back and forth transparently.

Regarding $, as your tests suggest, it only matches (an optional) \n.

Google "Understanding Newlines", it is an article in ONLamp that has examples in Perl, but it applies to Ruby.

···

Sent from my iPhone

On 01/10/2012, at 18:58, Roger Pack <lists@ruby-forum.com> wrote:

I believe "\r\n" is a normal newline for windows "type" files.

Should the following work, then, seeing as $ is supposed to mean "end of
line"?

"abc\r\n" =~ /abc$/

=> nil

This works:

"abc\n" =~ /abc$/

=> 0

I'm guessing it shouldn't, actually, and current behavior is expected.
Thanks!
-roger-

--
Posted via http://www.ruby-forum.com/\.

Ok thanks for the responses. I've filed a jruby bug since it appears
"\r\n" within the app (not on disk) isn't expected.
Thank you.
-r

···

--
Posted via http://www.ruby-forum.com/.

https://jira.codehaus.org/browse/JRUBY-6913 (it works as expected with
jdk6, but not jdk7)

···

--
Posted via http://www.ruby-forum.com/.

JRuby may have some gotcha because these semantics work on many languages (C, Perl, Python, ...) but not in Java.

In C printf("\n") is portable, stdio takes care of the translation on Windows, but in Java \n has no translation. In Java the portable way to print a newline is println.

I am pretty sure they addressed this years ago though and JRuby provides MRI semantics to the user. Which is the code that is not working?

···

Sent from my iPhone

On 01/10/2012, at 19:25, Roger Pack <lists@ruby-forum.com> wrote:

Ok thanks for the responses. I've filed a jruby bug since it appears
"\r\n" within the app (not on disk) isn't expected.
Thank you.
-r

--
Posted via http://www.ruby-forum.com/\.