M
Mmcolli00 Mom
count1 = Hash.new(0)
File.open("patient.txt") do |src|
src.each_line do |line|
word1 = line
count1[word1] += 1
end
end
words = (count1.keys).uniq
words.each do |word|
if word != /Date1|packageId/ then #<----------does not evaluate, i am
not sure if i am using hash correctly
#check for an odd count, which means a discrepancy
if (count1[word] == 1 or count1[word] == 3 or count1[word] == 5 or
count1[word] == 7 or count1[word] == 9 or count1[word] == 11 ) then
puts "Discrepancy: #{word}"
puts count1[word]
end
end
end
#~ This goes through the patient.txt and counts how many occurrences
that there are of each line
#~ if there is an even number of the same line then there is no
discrepancy, if there is an odd number
#~ then that means the file broke somewhere and there is a discrepancy.
I am checking for odd values using hard code, this
#~ is because I could not get the .odd? method to work. My question is
this, how can I output everything that I have now except for
#~ any line containing values packageId and Date1?
#~ Here is my output but I want to leave out any line with the word
'packageId and Date1' because these will be irrelevant differences.
#~ Discrepancy: packageId 234 <- remove
#~ 1
#~ Discrepancy: Date1 03/10/08 <-remove
#~ 1
#~ Discrepancy: packageId 454 <-remove
#~ 1
#~ Discrepancy: Date1 03/11/08 <-remove
#~ 1
#~ Discrepancy: bloodtype o <---------------Leave only values like this
#~ 3
#~ Discrepancy: Date1 04/02/08 <-remove
#~ 1
#~ Discrepancy: Date1 03/01/08 <-remove
#~ 1
#~ Discrepancy: personId 23 <-remove
#~ 3
#~ Discrepancy: Date1 03/02/08 <-remove
#~ 1
#~ Discrepancy: packageId 2345 <-remove
#~ 1
#~ Discrepancy: packageId 2345 <-remove
#~ 1
Attachments:
http://www.ruby-forum.com/attachment/3187/patient.txt
File.open("patient.txt") do |src|
src.each_line do |line|
word1 = line
count1[word1] += 1
end
end
words = (count1.keys).uniq
words.each do |word|
if word != /Date1|packageId/ then #<----------does not evaluate, i am
not sure if i am using hash correctly
#check for an odd count, which means a discrepancy
if (count1[word] == 1 or count1[word] == 3 or count1[word] == 5 or
count1[word] == 7 or count1[word] == 9 or count1[word] == 11 ) then
puts "Discrepancy: #{word}"
puts count1[word]
end
end
end
#~ This goes through the patient.txt and counts how many occurrences
that there are of each line
#~ if there is an even number of the same line then there is no
discrepancy, if there is an odd number
#~ then that means the file broke somewhere and there is a discrepancy.
I am checking for odd values using hard code, this
#~ is because I could not get the .odd? method to work. My question is
this, how can I output everything that I have now except for
#~ any line containing values packageId and Date1?
#~ Here is my output but I want to leave out any line with the word
'packageId and Date1' because these will be irrelevant differences.
#~ Discrepancy: packageId 234 <- remove
#~ 1
#~ Discrepancy: Date1 03/10/08 <-remove
#~ 1
#~ Discrepancy: packageId 454 <-remove
#~ 1
#~ Discrepancy: Date1 03/11/08 <-remove
#~ 1
#~ Discrepancy: bloodtype o <---------------Leave only values like this
#~ 3
#~ Discrepancy: Date1 04/02/08 <-remove
#~ 1
#~ Discrepancy: Date1 03/01/08 <-remove
#~ 1
#~ Discrepancy: personId 23 <-remove
#~ 3
#~ Discrepancy: Date1 03/02/08 <-remove
#~ 1
#~ Discrepancy: packageId 2345 <-remove
#~ 1
#~ Discrepancy: packageId 2345 <-remove
#~ 1
Attachments:
http://www.ruby-forum.com/attachment/3187/patient.txt