# IO#gets(sep\_string) usage

**URL:** <https://www.ruby-forum.com/t/io-gets-sep-string-usage/114709>\
**Category:** Ruby\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/io-gets-sep-string-usage/114709 "2007-09-17T13:24:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZyLo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@ZyLo](https://www.ruby-forum.com/u/ZyLo)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/io-gets-sep-string-usage/114709/1 "2007-09-17T13:24:38Z")

</div>

Hello all. I’m trying to use the gets function, only I want to read  
in a file and make separators any sort of punctuation(",", “:”, “\n”,  
etc.).

My problem is trying to understand how the sep\_string=$/ option is  
supposed to work:

ios.gets(sep\_string=$/)

How can I specify what sep\_string is so that when I do something for a  
while loop on gets, I can get each word instead of a line of text, or  
lines of text with various punctuation I don’t want?

A second note, I’m not sure what $/ is supposed to mean. Is that the  
separator for newline(which i thought was \n)?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ZyLo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@ZyLo](https://www.ruby-forum.com/u/ZyLo)\
**Post date:** [September 25, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/io-gets-sep-string-usage/114709/2 "2007-09-25T23:02:32Z")

</div>

On 9/16/07, ZyLo [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> while loop on gets, I can get each word instead of a line of text, or  
> lines of text with various punctuation I don’t want?
> 
> A second note, I’m not sure what $/ is supposed to mean. Is that the  
> separator for newline(which i thought was \n)?

$/ is the ‘output separator’ global. It defaults to \n.  
What that syntax is saying is that you can pass a separator string to  
IO#gets, and it will use it. If you don’t pass it one, it will use  
whatever $/ is set to.
