From: MonkeeSage Date: 2007-12-06T05:50:04+09:00 Subject: Re: hash On Dec 5, 2:28 pm, Johnathan Smith wrote: > hi, > > thanks, i've got it to print out the hash > although I'm getting a wierd output where its taking the first letter > off the surname e.g: > > >ruby main.rb > > 3 > {"ref1"=>["Book", "ittle, S R"], "ref2"=>["Journal", "mith, J"] > > can you see in my code where im going wrong? > also, is it possible to print the different refrences on new lines? > > ill provide my code below > thanks > > # > # > File.open('reference.txt').each do |line| > if line =~ /^tag:/i > $linecount += 1 > end > end > puts $linecount > # > # > # ^ This part is pointless now. $linecount above is equal to database.length in the code below. > File.open('reference.txt') { | handle |tags = > handle.read.split("\n\n") > for tag in tags > key, type, author = tag.split("\n") > database[key[5..-1]] = [type[6..-1], author[9..-1]] > end > } > p database > # > # > -- > Posted viahttp://www.ruby-forum.com/. It should have been author[8..-1], sorry about that. I suggest that you go through one of the many ruby guides/tutorials listed here: http://www.ruby-lang.org/en/documentation/ Regards, Jordan