IO#gets(sep_string) usage

Discussion in 'Ruby' started by ZyLo, Sep 16, 2007.

  1. ZyLo

    ZyLo Guest

    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.
    ZyLo, Sep 16, 2007
    #1
    1. Advertising

  2. On 9/16/07, ZyLo <> wrote:
    > 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)?
    >


    $/ 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.
    Wilson Bilkovich, Sep 16, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    5
    Views:
    517
    Steven Saunderson
    Jul 10, 2006
  2. jayapal

    why the usage of gets() is dangerous.

    jayapal, Nov 16, 2007, in forum: C Programming
    Replies:
    123
    Views:
    1,973
    CBFalconer
    Nov 28, 2007
  3. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    348
    John Joyce
    Mar 26, 2007
  4. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    188
    John Joyce
    Apr 23, 2007
  5. libsfan01
    Replies:
    5
    Views:
    235
    Jeff North
    Dec 20, 2006
Loading...

Share This Page