Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Trying to write a first plain ruby script
Jesse Crockett
7/11/2008 8:06:00 AM
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-...
.
2 Answers
Axel Etzold
7/11/2008 10:04:00 AM
0
-------- 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-...
.
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/mult...
Jesse Crockett
7/11/2008 5:04:00 PM
0
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 :-)
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Trying to write a first plain ruby script
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password