From: Peter Miller Date: 2010-04-10T07:25:01+09:00 Subject: Re: read and write stock prices to file using arrays well, I just got home from work and was going to hack away.. but instead i cut n paste and got a working script after a couple minor edits. Thanks so much for such a complete solution. I wasn't expecting that! Here is the working code in full. It handles my file perfectly. require 'rubygems' require 'yahoofinance' quote_type = YahooFinance::StandardQuote filename = ARGV[0] TickerData = Struct.new :symbol, :file_position, :name, :last_trade lines = File.readlines(filename) tickers = {} lines.each_with_index do |line, i| next if line =~ /^#/ # skip comments next if line.chomp.empty? # skip empty lines symbol = line[/\w+/].upcase tickers[symbol] = TickerData.new symbol, i #store the symbol and file position end YahooFinance.get_quotes( quote_type, tickers.keys ) do |qt| next unless tickers[qt.symbol] tickers[qt.symbol].name = qt.name tickers[qt.symbol].last_trade = qt.lastTrade end tickers.each do |symbol, ticker| lines[ticker.file_position] = "#{ticker.symbol} #{ticker.name} #{ticker.last_trade}\n" end File.open(filename, "w") {|file| file.puts lines.join} Off to do some reading on structs Thanks Martin and Jesus -- Posted via http://www.ruby-forum.com/.