From: "David A. Black" Date: 2010-07-10T08:55:37+09:00 Subject: Re: FIRST PROGRAMMING PROBLEM Array Hi -- On Sat, 10 Jul 2010, brabuhr@gmail.com wrote: > (One way that) You could modify it to put each line in an array like: > > a = [] > f=File.open(txtFile) > f.each do |line| > a << line > end > f.close > > Of course, in your case you would want to extract the tokens from the > line and stick them in the array instead. Don't forget too that File objects are fully enumerable, so you don't have to maintain an explicit accumulator array -- you can use map instead: def get_tokens_from_file(filename) File.open(filename) do |f| f.map do |line| get_tokens_from_line(line) end end end token_array = get_tokens_from_file(filename) or similar. David -- David A. Black, Senior Developer, Cyrus Innovation Inc. The Ruby training with Black/Brown/McAnally Compleat Stay tuned for next event announcement! Rubyist http://www.compleatrubyist.com