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.
if word != /Date1|packageId/ then #<----------does not evaluate, i am
not sure if i am using hash correctly
This has nothing to do with hashes. word is a string /Date1|packageId/ is a
regexp. They will never be equal. I'm pretty sure you want !~ ("does not
match") instead of != ("is not equal to") there.
if word != /Date1|packageId/ then #<----------does not evaluate, i am
not sure if i am using hash correctly
This has nothing to do with hashes. word is a string /Date1|packageId/
is a
regexp. They will never be equal. I'm pretty sure you want !~ ("does not
match") instead of != ("is not equal to") there.
HTH,
Sebastian
I thought a reg expression could be used on any string. I am confused.
So if my Date1 has any value after it, I will have to have a string
wildcard, correct? What are you all using for wildcards? Thanks, MC
* Sebastian Hungerecker <sepp2k@googlemail.com> (2009-01-20) schrieb:
Mmcolli00 Mom wrote:
if word != /Date1|packageId/ then #<----------does not evaluate, i am
not sure if i am using hash correctly
This has nothing to do with hashes. word is a string /Date1|packageId/ is a
regexp. They will never be equal. I'm pretty sure you want !~ ("does not
match") instead of != ("is not equal to") there.
Shouldn't the statement above always be executed then?
So if my Date1 has any value after it, I will have to have a string
wildcard, correct? What are you all using for wildcards? Thanks, MC
I don't know what you mean.
Well what I meant was that I don't understand how to check if a line in
the text file contains at least 'Date1'.
So anytime it the line has at least contains Date1, then it should be
ignored in my code. I thought that I could use the regular expression
such as:
if word != /Date1/
however, I can't use the reg ex and don't know how to do that with a
string. I was thinking there is a wild card so that I could use
something like: if word !~ "Date1*" with '*' being any value after
Date1.
So if my Date1 has any value after it, I will have to have a string
wildcard, correct? What are you all using for wildcards? Thanks, MC
I don't know what you mean.
Well what I meant was that I don't understand how to check if a line in the text file contains at least 'Date1'.
So anytime it the line has at least contains Date1, then it should be ignored in my code. I thought that I could use the regular expression such as:
if word != /Date1/
if word !~ /Date1/
however, I can't use the reg ex and don't know how to do that with a string. I was thinking there is a wild card so that I could use something like: if word !~ "Date1*" with '*' being any value after Date1.
Again, if you want to do regexp matching you need to use operators "=~", "===" or "!~" but NOT "==" or "!="! These are totally different things.
robert
···
On 21.01.2009 03:11, Mmcolli00 Mom wrote:
--
remember.guy do |as, often| as.you_can - without end
If you want to check only whether line contains 'Date1' you can simply
use
line.include? 'Date1'
···
On Jan 21, 3:11 am, Mmcolli00 Mom <mmc_coll...@yahoo.com> wrote:
>> So if my Date1 has any value after it, I will have to have a string
>> wildcard, correct? What are you all using for wildcards? Thanks, MC
> I don't know what you mean.
Well what I meant was that I don't understand how to check if a line in
the text file contains at least 'Date1'.
So anytime it the line has at least contains Date1, then it should be
ignored in my code. I thought that I could use the regular expression
such as:
if word != /Date1/
however, I can't use the reg ex and don't know how to do that with a
string. I was thinking there is a wild card so that I could use
something like: if word !~ "Date1*" with '*' being any value after
Date1.
Thanks, MC
--
Posted viahttp://www.ruby-forum.com/.