Extracting multiple lines from a file

Ron Coutts wrote:

file = File.open(“ordinal”)
while file.gets
print if /third/ … /fifth/
End

Unfortunately this code snippet is buggy as it prints out all ten
lines
of the file, not just lines three through five as mentioned in the
book.
So I’m still stuck on this problem.

This works for me; no bug that I can see.

However, this “range” functionality might be going away in Ruby 2, so
don’t depend on it. I happen to disagree with this change, but…
it’s not up to me.

···

Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

What version of Ruby are you running? I’m seeing the same behavior
as Ron in 1.8.1p3, 2003-12-05 build. It prints every line in the file.

-Mark

···

On Tue, Dec 16, 2003 at 07:25:15AM +0900, Michael Campbell wrote:

Ron Coutts wrote:

file = File.open(“ordinal”)
while file.gets
print if /third/ … /fifth/
End

Unfortunately this code snippet is buggy as it prints out all ten
lines
of the file, not just lines three through five as mentioned in the
book.
So I’m still stuck on this problem.

This works for me; no bug that I can see.