Force newline only on Windows

How can I force \n in my strings to be *only* a newline character and not a
carriage return/newline combination on Windows?

Thanks,
Steve

Hi 'talk!

Is there anything in Rubyland like SciPy?

URL: http://www.scipy.org/About/

In short, it is a collection of scientific tools, combining a lot of
numeric functions, data visualization/plotting routines etc into a
single package. (The part I liked was about how it can transform the
Python command line interpreter to a very capable Math/Analysis tool)

Does any combination of Ruby libraries offer the same sort of functionality?

Thanks in advance!
Shajith

PS: Apologies if this sounds like another of those "Ruby vs Python" things.

PS1: Right now, I am aware of Narray. I'm also looking for some more
functionality(optimization?, plotting, etc)

"Steve V" <ruby@digitalnothing.com> schrieb im Newsbeitrag
news:LDEHKBBOEMIJKHKBOFNFCEHPNBAA.ruby@digitalnothing.com...

How can I force \n in my strings to be *only* a newline character and

not a

carriage return/newline combination on Windows?

It's always just a newline in strings. I guess you mean you want the \n
in a file written:

09:14:10 [temp]: irb
irb(main):001:0> File.open("x","wb") {|io| io.puts "foo\nbar"}
=> nil
irb(main):002:0> exit
09:15:51 [temp]: od -t c x
0000000 f o o \n b a r \n
0000010
09:15:56 [temp]:

Kind regards

    robert

Steve V wrote:

How can I force \n in my strings to be *only* a newline character and not a
carriage return/newline combination on Windows?

Use "binary" mode when opening your file, or invoke the "binmode" method on your IO object.

   File.open("x.txt", "wb") do |file|
     file.print "\n"
   end

On Windows, x.txt will contain only "\n". If you leave out the "b", you will get "\r\n" instead.

   STDOUT.binmode
   print "\n"

This will make the same change to stdout.

ยทยทยท

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoil.com/&gt;