# Kernel#p and output record separator

**URL:** <https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902>\
**Category:** Ruby\
**Created:** [July 11, 2006, 9:19am UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902 "2006-07-11T09:19:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 11, 2006, 9:19am UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902/1 "2006-07-11T09:19:29Z")

</div>

Hi.

ri Kernel#p shows this:

## --------------------------------------------------------------- Kernel#p p(obj, …) =\> nil

```
 For each object, directly writes _obj_.+inspect+ followed by the
 current output record separator to the program's standard output.

    S = Struct.new(:name, :state)
    s = S['dave', 'TX']
    p s

 _produces:_

    #<S name="dave", state="TX">

```

But when I run the following:

$cat tmp.rb  
print $  
$ ruby tmp.rb  
nil$

Namely, Kernel#p is expected to print ‘current output record separator’,  
but current output separator is just _nil_.

What I’ve done in the wrong way here? Is the ri document written  
wrongly?

Sincerely,  
Minkoo S.

---

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 11, 2006, 9:28am UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902/2 "2006-07-11T09:28:57Z")

</div>

On Tuesday 11 July 2006 16:16, Minkoo S. wrote:

> ```
> S = Struct.new(:name, :state)
> 
> ```
> 
> print $  
> $ ruby tmp.rb  
> nil$
> 
> Namely, Kernel#p is expected to print ‘current output record separator’,  
> but current output separator is just _nil_.
> 
> What I’ve done in the wrong way here? Is the ri document written wrongly?

manveru@pi ~\> irb  
p $  
nil

# nil

p $/  
“\n”

# nil

guess you just have a typo there 🙂  
remember, the $/ is a jedi that just waits to attack and to slice  
output…  
it’s not the output being attacked 🙂

stupid way to remember… but maybe it helps - imho one shoulnd’t have  
to  
remember that stuff anyway

---

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 12, 2006, 6:31am UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902/3 "2006-07-12T06:31:20Z")

</div>

I should have to mention this problem explicitly.

AFAIK, $/ is ‘input record separator’ while $\ is ‘output record  
separator.’  
And the problem is:

$ruby -e ‘p “a”’  
“a”  
$

As you can see p is printing new line character. But the spec says that  
p is supposed to print ‘output record separator’ after printing out  
given  
arguments.

Let’s see what current output record separator is…

$ruby -e ‘p $’  
nil  
$

Surprisingly, $, output record separator, is nil while Kernel#p printed  
new  
line.

So I guess one of the following holds:  
(1) p prints new line instead of output record separator.  
(2) Somehow, $\ is converted into newline while Kernel#p is running  
(3) $\ is not a output record separator, actually.

Any idea?

- Minkoo S.

---

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 12, 2006, 12:09pm UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902/4 "2006-07-12T12:09:14Z")

</div>

On 7/12/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > $ruby -e ‘p “a”’
> > 
> > (2) Somehow, $\ is converted into newline while Kernel#p is running
> 
> I think maybe the docs lie. Looking at the C code, p uses  
> rb\_default\_rs (when maybe they meant to use rb\_output\_rs?)

Could anybody tell me where I have to file the bug report on the  
document of ‘Kernel#p’?

Sincerely,  
Minkoo S.

---

<div class="post-metadata">

**Author:** ![pool007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3bc359/32.png) [@pool007](https://www.ruby-forum.com/u/pool007)\
**Post date:** [July 12, 2006, 7:14am UTC](https://www.ruby-forum.com/t/kernel-p-and-output-record-separator/97902/5 "2006-07-12T07:14:53Z")

</div>

On Jul 12, 2006, at 12:30 AM, Minkoo S. wrote:

> As you can see p is printing new line character. But the spec says
> 
> - Minkoo S.

Ack, top posting evil.

$\ is the output record separator if print is any indicator

% cat outputsep.rb  
$\ = “:”  
print 1  
puts

% ruby outputsep.rb  
1:

I think maybe the docs lie. Looking at the C code, p uses  
rb\_default\_rs (when maybe they meant to use rb\_output\_rs?)
