From: Thomas Chust Date: 2009-08-08T03:27:53+09:00 Subject: Re: How do I add ? 2009/8/7 Rob Biedenharn : > [...] > puts File.readlines('some_file.txt').inject(0) {|total,line| total + > line.split("\t")[1].to_i } > > (but if the file is large, that could be terribly inefficient) > [...] Hello, inject is a method of Iterable, so it's unnecessary to read the whole file into memory first to use it. I would prefer a solution that is both elegant and efficient: puts file.inject(0) {|acc, line| acc + line.split(/\t/)[1].to_f } cu, Thomas -- When C++ is your hammer, every problem looks like your thumb.