From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-06-22T03:43:31+09:00 Subject: Re: reading text line On Sat, 21 Jun 2003 21:21:24 +0200, Simon Strandgaard wrote: > On Sat, 21 Jun 2003 11:39:20 +0000, Shashank Date wrote: > >> >> "Shashank Date" wrote in message >>> f = File.open("testfile","r") >>> while(!f.eof) >>> s = f.gets >>> puts s >>> f.gets >>> end >>> f.close >> >> Two one-liners (again ignoring exception handling, of course): >> >> File.open("junk.txt","r") {|f| (puts f.gets; f.gets) while !f.eof} >> >> File.readlines("junk.txt").each_with_index{|line,i| puts line if (i % 2 == >> 0)} > > > file = __FILE__ > ok = true > res = IO.readlines(file).reject { |obj| ok = !ok } > p res Even better.. you can use 'partition' instead file = __FILE__ ok = true res1, res2 = IO.readlines(file).partition { |obj| ok = !ok } p res1, res2 -- Simon Strandgaard