Trying to write a first plain ruby script

J

Jesse Crockett

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.
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Fri, 11 Jul 2008 17:05:54 +0900
Von: Jesse Crockett <[email protected]>
An: (e-mail address removed)
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.

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
 
J

Jesse Crockett

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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top