Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: improperly exiting loop with DATA and __END__
7stud --
10/26/2007 11:40:00 PM
Robert Keller wrote:
> I have this bit of code that loops through the __END__ data and does
> some time sheet processing. All that bit works, but when I get to the
> end of the "DATA" I get an error about calling split for a
> nil:NilClass...I an sure it is because I am trying to process the last
> record which is an empty string.
Not quite. After the last line of the file has been read, if you call
gets() again, it returns nil. If your last line was really a blank
line, you wouldn't get an error:
line = ""
processed_line = line.chomp.split(",")
puts "--->#{processed_line}<----"
output:
---><----
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: improperly exiting loop with DATA and __END__
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