From: 7stud -- Date: 2007-10-28T09:28:57+09:00 Subject: Re: NOT reading an entire file into memory Devi Web Development wrote: > I have heard that File.readline is in fact equivalent to > File.read.split('\n').each, which would really ruin my purpose of not > loading the whole file. > I doubt that is true, but as is often the case with Ruby there is no easily locatable documentation that describes File I/O buffering. Just in case, here is another solution: #create a data file containing: #line 1 #line 2 #... #line 10 File.open("data.txt", "w") do |file| 10.times do |i| file.puts("line #{i+1}") end end #read lines 4-7 and display them: File.open("data.txt") do |file| file.each_with_index do |line, i| i = i + 1 #i starts at 0 if i < 4 next elsif i < 8 puts line else break end end end -- Posted via http://www.ruby-forum.com/.