From: Parker Selbert Date: 2010-08-12T06:49:24+09:00 Subject: Re: how to print an array Francisco Martinez wrote: > def cargar_tokens(txtFileName) > tokens=[] > txtFile = File.open(txtFileName) > txtFile.each(" ") do |palabra| > if (palabra=~ /(.+)/) > token = $1 > tokens.push(token) > end > end > txtFile.close > return tokens > end > > > if (ARGV.length<1) > puts "I need one argument: 1) name of the file" > else > tokens=cargar_tokens(ARGV[0]) > end It looks like Brian answered your question, but if you are interested in the more idiomatic "ruby" approach you can do something more like: def cargar_tokens(txt_file_name) tokens = [] File.open(txt_file_name) do |file| file.each_line(' ') { |palabra| tokens << $1 if palabra =~ /(.+)/ } end tokens end if ARGV.empty? puts "I need one argument: 1) name of the file" else tokens = cargar_tokens(ARGV.first) end The nice rubyisms are what make it fun, to me at least! -- Posted via http://www.ruby-forum.com/.