From: Peter Miller Date: 2010-04-09T22:57:30+09:00 Subject: Re: read and write stock prices to file using arrays > ticker = [] > lines.each do |line| > next if line =~ /^#/ # skip comments > next if line.chomp.empty? # skip empty lines > ticker << line > end > ticker << line.split(" ")[0] # or maybe line[/\w+/] Thank you. The ticker << line is really helpful. > An idea would be to fill a hash with the data retrieved for each symbol: > > ticker_data = {} > > YahooFinance.get_quotes( quote_type, quote_symbols ) do |qt| > puts "QUOTING: #{qt.symbol}" > puts "#{qt.name}" > puts "#{qt.lastTrade}" > ticker_data[qt.symbol] = [qt.name, qt.lastTrade] > end I didn't realize a hash could point to more than one object. Awesome. > and then write to the file the data in ticker_data. I can see > additional complexity if you want to keep the file exactly as it is > (with the comments) but inserting the retrieved data in place. The > easiest would be to just write ticker_data: this is why i was trying to do $ticker[lines] = line when storing the data. I thought I could point the index of the ticker symbol, which would tell me what line it was on, to my array $ticker. Then i wanted to use that index to write back the ticker data to the same line it came from. i think i need to capture the tickers position in the file at this point ticker << line and then somehow use it when writing the file back. I'm going to work on that, but if there is another approach, or my thinking is flawed, a nudge in the right direction would be nice. The hardest part of learning to code for me is thinking like a computer. Thanks for the help Jesus. -- Posted via http://www.ruby-forum.com/.