Tim Wolak wrote: > Hmm ok then maybe changing the keys is not what I need to do then. > > The reason I have skty and sktyny is that those are account names, sorry > should have stated that earlier. So I have a list of account numbers > and their balances, all accounts listed 500 through 539 should have a > key of skty and accounts with 540 through 550 should be sktyny. All the > account balances for skty should be combined into the value for skty > and all the balances should be combined for teh value of sktyny. Here > is the full code, I did not want to post a mile long request with it > all in there. > #Create a hash so a non-existent key returns #the default value 0: results = Hash.new {|hash, key| hash[key] = 0} key1 = "skty" range1 = 500..539 key2 = "sktyny" range2 = 540..550 DATA.each_line do |line| acct_str, balance_str = line.split acct = acct_str.to_i balance = balance_str.to_f if range1 === acct results[key1] += balance elsif range2 === acct results[key2] += balance else results[acct] = balance end end p results __END__ 440 550.25 539 22.25 500 10.50 540 100.00 550 225.00 100 300.00 --output:-- {"sktyny"=>325.0, 440=>550.25, 100=>300.0, "skty"=>32.75} -- Posted via http://www.ruby-forum.com/.