Trying to write a first plain ruby script

In irb, the method "one\ntwo\nthree".split worked fine

but in a file..

···

-------------------------------
@text = "

line one
line two
line three
"

@lines = @text.split(/\n/)
-------------------------------

.. it fails: "private method `split' called for nil:NilClass
(NoMethodError)"

After getting the array of lines, again I need to call split() on each
line, then joing them with ", "

(basically I need a CSV file for 14,000 lines verb annotation from
WordNet)

It's late, so I probably could not figure this out myself tonight. Any
help is welcome. Thank you.
--
Posted via http://www.ruby-forum.com/.

-------- Original-Nachricht --------

Datum: Fri, 11 Jul 2008 17:05:54 +0900
Von: Jesse Crockett <tefflox@gmail.com>
An: ruby-talk@ruby-lang.org
Betreff: Trying to write a first plain ruby script

In irb, the method "one\ntwo\nthree".split worked fine

but in a file..
-------------------------------
@text = "

line one
line two
line three
"

@lines = @text.split(/\n/)
-------------------------------

.. it fails: "private method `split' called for nil:NilClass
(NoMethodError)"

After getting the array of lines, again I need to call split() on each
line, then joing them with ", "

(basically I need a CSV file for 14,000 lines verb annotation from
WordNet)

It's late, so I probably could not figure this out myself tonight. Any
help is welcome. Thank you.
--
Posted via http://www.ruby-forum.com/\.

Dear Jesse,

I cannot reproduce your error on Ubuntu Linux ... did you really post the exact text/code ?
What operating system are you working on ? I suspect that the line breaks might be \r\n instead
of just \n (especially if the text file was created on Windows), and that

@lines = @text.split(/\n|\r\n/)

would work.

Best regards,

Axel

···

--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Heh. It was even later than I thought. The problem was that I called
the text string "@index_verbs" and had been trying to call `split' on
"@verb_index"

I can probably accomplish the rest of the script today :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.