From: Adam Nelreth Date: 2010-03-25T19:16:36+09:00 Subject: Re: hash problem F. Senault wrote: > Le 25 mars � 10:29, Adam Nelreth a �crit : > >> but this doesn't work :/ > > It should. Show us your whole code, not just snippets - the problem > lies somewhere else. > >>> h = Hash.new(0) > => {} >>> if h.has_key?("1.2.3.4") >>> puts "In table." >>> else > ?> h["1.2.3.4"] = 1 >>> end > => 1 >>> if h.has_key?("1.2.3.4") >>> puts "In table." >>> else > ?> h["1.2.3.4"] = 1 >>> end > In table. > => nil >>> h.has_key?("1.2.3.4") > => true > > Fred Ok - here is code: login = 'aaa' test = Hash.new imap = Net::IMAP.new('imap-server',993,true) puts "passwd: " pass = gets.chop imap.login(login,pass) imap.select('example') imap.uid_search(["SUBJECT", "To-check", "NOT", "SEEN"]).each do |uid| mess = imap.uid_fetch(uid, "ENVELOPE")[0].attr["ENVELOPE"] title = mess.subject ip = /(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/.match(title) if test.has_key?(ip) test[ip] += 1 else test[ip] = 1 end end imap.logout() imap.disconnect() I try with else test[ip] = 1 and without else - it still doesn't work like I need - maybe there is problem with "" or '' because I don't set it when I put key to hash table -- Posted via http://www.ruby-forum.com/.