[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
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-....