I have worked out the problem but I am a little unsure how to solve it. We have counts which holds all of the event ID's, however |d, cnt| is not counting the number of matching ID numbers and it just assigns each ID the number 1. So given this example, we would expect cnt to find the ID of ?? as occuring more than 5 times and ignore the rest: MonFeb022009 MonFeb022009 MonFeb022009 MonFeb022009 MonFeb022009 MonFeb022009 MonFeb022009 TueAug052008 TueAug052008 WedAug062008 However instead cnt is ust placing the number 1 for each ID for example 1 1 1 1 1 1 1 1 1 1 Can anyone help me with a fix? Many thanks Stuart Clarke wrote: > Thanks Robert. > > This is more to what I need. However I am still getting no result, > everything works until we get to this section: > >> counts = Hash.new(0) >> eventdateID.each {|d| counts[d] +=1} >> counts.each do |d,cnt| >> @alerts.push("#{event.event_id} #{@tab} #{event.time_written} >> #{@tab}#{event.event_type} #{@tab} #{type}") if cnt >= 5 >> end > > Does it make any difference that the data being read into the > eventdateID is alphanumeric eg: > > MonFeb022009 > MonFeb022009 > MonFeb022009 > > Many thanks. > > > Robert Klemme wrote: >> On 02.02.2009 21:43, Stuart Clarke wrote: >>> end >> You probably rather want >> >> eventdateID.push eventsbydate.gsub(/\s/, '')[0..7] + >> eventsbydate[26..30] >> counts = Hash.new(0) >> eventdateID.each {|d| counts[d] +=1} >> counts.each do |d,cnt| >> @alerts.push("#{event.event_id} #{@tab} #{event.time_written} >> #{@tab}#{event.event_type} #{@tab} #{type}") if cnt >= 5 >> end >> >> Cheers >> >> robert -- Posted via http://www.ruby-forum.com/.