From: "Peña, Botp" Date: 2008-03-06T16:53:14+09:00 Subject: Re: Too many open files on OpenBSD On Behalf Of Damjan Rems: # Yukihiro Matsumoto wrote: # > def parse() # > File.read(@path).each_line do |line| # > line =~ /^(.*?) (.*)/ # > # > .... # > end # > end # # Or even better: # # def parse() # lines = File.open(@path) {|f| f.read} # lines.each_line do |line| # line =~ /^(.*?) (.*)/ # # .... # end # end # # With File.open file gets closed automaticly after block is processed. File.read will also auto close, in fact it does not need a block :) and you can specify length and offset, too. botp@pc4all:/root$ qri IO.read --------------------------------------------------------------- IO::read IO.read(name, [length [, offset]] ) => string ------------------------------------------------------------------------ Opens the file, optionally seeks to the given offset, then returns length bytes (defaulting to the rest of the file). read ensures the file is closed before returning. .... so basically, File.read(@path) and lines = File.open(@path) {|f| f.read} do same thing, but i prefer the former in this case, obviously... kind regards -botp