------ art_152654_15397735.1165848030266 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 12/11/06, James Edward Gray II <james / grayproductions.net> wrote: > > On Dec 11, 2006, at 7:02 AM, Pedro Fortuny Ayuso wrote: > > > I would do somethink like: > > > > a ile.open("name_of_file") > > whole_file .inject("") {|s,e| s+e} > > a.close That's a long way to say: > > whole_file ile.read("name_of_file") Thanks! I kew it (and the rest) had to be suboptimal. (... etc ...) Pedro > However, if you are doing stuff *line by line* you had better do > > sth like > > > > a ile.open("name_of_file") > > a.each do |line| > > YOUR STUFF WITH line > > end > > a.close > > File.foreach("name_of_file") do |line| > # ... use line here > end > > > For example, you want to count the number of lines where the word > > "foo" > > appears > > > > a ile.open("myfile") > > count > > a.each do |line| > > count + if line /foo/ > > end > > a.close > > > > count has now that value. > > count > File.foreach("myfile") do |line| > count + if line /foo/ > end > > James Edward Gray II > > > -- Pedro Fortuny Ayuso C/Capuchinos 14, 1. 47006 Valladolid. SPAIN http://pfortuny.sdf-eu.org ------ art_152654_15397735.1165848030266--