Ricardo Furgeson wrote: > Hello everybody, > > Ruby is my first prgramming lenguage. I know it's a simple question so > I hope someone can help me out. I have a file that i need to read, > here's my code so far: > > class Parser > > File.open("Data") do |file| > while line = file.gets > > > > > end > end > > end > > somewhere in my file there is a table of strings like this: > > "Hello" = "hi miguel" > "wrong" = "this is not the right anser" > "correct asnwer" = "this is the right asnwer" > "for what" = "tell me what you need it for" > > My problem is this: > I want o search for this table, and read in such a way so that when I > call for a value(example, hello I can get its value, which is 'hi > miguel'). > > I know it's a straigt forward process. I'm not sure how to search for > the table, and wheather to use a hash or arrays. Can anyone help me > out? table = {} IO.foreach('Data') { |line| if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x table[ $1 ] = $2 end } puts table[ "wrong" ]