I have this small snipped of code.
I don’t know ruby and I think this is a great opportunity to apply it.
I want to print all the lines in file e which are not in file c. Each line is a number.
This is what I’ve got:
e = File.new('e').readlines
c = File.new('c').readlines
x = e.collect do |item|
c.include?( item ) ? "" : item
end
p x.sort
The problem is that both file may have empty spaces and for that reason the same number may not be considered as such. ( eg. “1234 ” is different from ” 1234 ” )
What do I need in my code to fix it? I’ve tried c.include?(item.strip) .. .but doesn’t seems to work.
Perhaps doing the
stripwhen you do thereadlineswould help, i.e.Then you could use
collectas you did, or perhapsselectif you don’t want the empty strings:Edit: or as Benno suggests, use