# Different behavior of '$,' output separator in Ruby 1.9

**URL:** <https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649>\
**Category:** Ruby\
**Created:** [March 5, 2010, 8:04pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649 "2010-03-05T20:04:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 5, 2010, 8:04pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/1 "2010-03-05T20:04:14Z")

</div>

In switching to Ruby 1.9 from 1.8 I notice that the behavior of the ‘$,’  
output separator has changed. In Ruby 1.9 the output separator is  
placed after a newline character, but this didn’t happen with Ruby 1.8.  
Using the following code:

* * *

$, = ', ’

data = [[‘a’, ‘b’, ‘c’], [‘1’, ‘2’, ‘3’], [‘x’, ‘y’, ‘z’]]

file\_out = File.new(“test.csv”, “w”)

data.each do |elem|  
file\_out.print elem[0], elem[1], elem[2], “\n”  
end

## file\_out.close

and running with Ruby 1.8 produces a file that contains

a, b, c,  
1, 2, 3,  
x, y, z,

but with Ruby 1.9 the contents of the file look like

a, b, c,  
, 1, 2, 3,  
, x, y, z,  
,

Is this an intentional change of behavior?  
–Alex

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 5, 2010, 8:47pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/2 "2010-03-05T20:47:20Z")

</div>

On 3/5/10, Alex DeCaria [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In switching to Ruby 1.9 from 1.8 I notice that the behavior of the ‘$,’  
> output separator has changed. In Ruby 1.9 the output separator is  
> placed after a newline character, but this didn’t happen with Ruby 1.8.

That doesn’t seem right.

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 5, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/3 "2010-03-05T20:56:27Z")

</div>

Alex,

## If you make a few minor modifications:

$, = ', ’  
$\ = “\n” ### output record separator ###

data = [[‘a’, ‘b’, ‘c’], [‘1’, ‘2’, ‘3’], [‘x’, ‘y’, ‘z’]]

file\_out = File.new(“test.csv”, “w”)

data.each do |elem|  
file\_out.print elem[0], elem[1], elem[2] ### no newline FIELD ###  
end

## file\_out.close

then you will get what you want in Ruby 1.9.  
a, b, c,  
1, 2, 3,  
x, y, z,  
I have not tried it in Ruby 1.8.

Looks like it is adding the output field separator AFTER the newline  
FIELD.

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 6, 2010, 3:34pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/4 "2010-03-06T15:34:34Z")

</div>

On 03/05/2010 08:46 PM, Caleb C. wrote:

> On 3/5/10, Alex DeCaria [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > In switching to Ruby 1.9 from 1.8 I notice that the behavior of the ‘$,’  
> > output separator has changed. In Ruby 1.9 the output separator is  
> > placed after a newline character, but this didn’t happen with Ruby 1.8.
> 
> That doesn’t seem right.

I agree. 1.9 writes one field separator too much. This must be a bug.

Alex, separators are intended to be used a tad differently. You would  
rather set the output record separator as well:

robert@fussel:~$ ruby -e ‘$,=“@”;$=“NL\n”;print 1,2,3’  
1@2@3NL  
robert@fussel:~$

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 7, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/5 "2010-03-07T13:09:56Z")

</div>

Should I submit a bug report, or do you think it will be eventually  
noticed on this forum?  
–Alex

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 7, 2010, 6:15pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/6 "2010-03-07T18:15:54Z")

</div>

On 03/07/2010 01:09 PM, Alex DeCaria wrote:

> Should I submit a bug report, or do you think it will be eventually  
> noticed on this forum?

I’d check whether that bug is known already and only file in cast it is  
not:  
[http://redmine.ruby-lang.org/projects/show/ruby-191](http://redmine.ruby-lang.org/projects/show/ruby-191)

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 7, 2010, 6:16pm UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/7 "2010-03-07T18:16:29Z")

</div>

On 3/7/10, Alex DeCaria [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Should I submit a bug report, or do you think it will be eventually  
> noticed on this forum?

File a bug.

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 13, 2010, 8:01am UTC](https://www.ruby-forum.com/t/different-behavior-of-output-separator-in-ruby-1-9/184649/8 "2010-03-13T08:01:29Z")

</div>

Hi,

In message “Re: Different behavior of ‘$,’ output separator in Ruby 1.9”  
on Sat, 6 Mar 2010 04:06:22 +0900, Alex DeCaria  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|In switching to Ruby 1.9 from 1.8 I notice that the behavior of the ‘$,’  
|output separator has changed. In Ruby 1.9 the output separator is  
|placed after a newline character, but this didn’t happen with Ruby 1.8.

Sorry it was a bug introduce in r11003. Fixed in r26906.

```
          matz.

```
