Robert Klemme
12/13/2006 10:07:00 PM
On 13.12.2006 19:04, Daniel Berger wrote:
> Wes Gamble wrote:
>> I need to write a CSV file and I know that I always want Windows style
>> newlines on it (for import into Excel).
>
> The line endings shouldn't matter. I write csv files on Linux systems
> all the time, and open them with Excel without issue.
>
>> I want to make sure that every line is terminated with "\r\n" (CRLF)
>> regardless of platform. How do I write the "\n" when the code executes
>> on Windows without ending up with \r\r\n at the end of every line?
>
> If you still really want to do this, you can set $/ (record separator)
> to "\r\n".
You sure this works?
$ ruby -e '$/="\r\n"; puts "foo", "bar"' | od -c
0000000 f o o \n b a r \n
0000010
Output record separator doesn't seem to help either:
$ ruby -e '$\="\r\n"; puts "foo", "bar"' | od -c
0000000 f o o \n b a r \n
0000010
Explicit works:
$ ruby -e 'print "foo\r\n", "bar"' | od -c
0000000 f o o \r \n b a r
0000010
$ ruby -v
ruby 1.8.5 (2006-08-25) [i386-cygwin]
Hm... Is this a bug in Ruby 1.8.5 or am I missing something?
robert