2009/8/17 botp <botpena / gmail.com>:
> On Mon, Aug 17, 2009 at 10:03 AM, Derek
> Smith<derekbellnersmith / yahoo.com> wrote:
>> How can I use a while loop in such as way where I want to process the
>> file until EOF?
>
> on your case, you do not need the EOF sig. Pls read on ruby's
> iterators and File.
>
>>....
>> File.open(mailog, 'r+').each { |line|
>> =A0 =A0 =A0 =A0while !mailog.eof?
>> =A0 =A0 =A0 =A0 =A0 =A0if line =3D~ /^#{last_record}/o
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0p line
>> =A0 =A0 =A0 =A0 =A0 =A0end
>> =A0 =A0 =A0 =A0end
>> }
>
>
> try eg,
>
> File.open( "maillog" ).each do |line|
> =A0p line if line =3D~ /^#{last_record}/
> end

You're not closing the file handle properly. :-)

Better:

File.foreach "maillog" do |line|
  p line if /^#{last_record}/o =3D~ line
end

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/