From: "Jesús Gabriel y Galán" Date: 2010-11-09T02:23:11+09:00 Subject: Re: Comparing/search struct array On Mon, Nov 8, 2010 at 6:14 PM, Josh Cheek wrote: > 2010/11/8 Szabolcs Tóth > f = File.open("report.output", 'r').each {|line| >>  if line =~ /MST Revenue/ >> >> > Tricky to find this one in the docs, its actually under IO rather than File > http://ruby-doc.org/core/classes/IO.html#M002239 "If the optional code block > is given, it will be passed *io* as an argument, and the > IOobject will automatically > be closed when the block terminates." So you can > let File close the file for you (this is considered a best practice, since > it does certain things to ensure this will happen, even if an error is > raised) > > File.open 'report.output' do |file| >  file.each do |line| >    ... >  end > end If you are not doing anything else with the file apart from reading the lines you could also do: File.foreach("report.output") do |line| ... end Jesus.