From: Brian Candler Date: 2008-12-03T06:21:22+09:00 Subject: Re: How do you read text file by creating a Hash in a script? Mmcolli00 Mom wrote: > This is some example contents of my text file: logzT09.txt > > 00834 tue z0sdf > 01230 wed z0sdf > 34234 tue wet0f > > How can I read this in another ruby script by using an Hash? Do you mean, how to read it into a Hash? Just read the file one line at a time, splitting it into key and value as you desire, and then add that as a new element into the Hash. Methods you may find useful: File.open each_line (for an IO object, yields a string for each line) chomp (for a String object, chop off the final newline) split (for a String object, split by default on spaces) Hash methods: h = {} # create an empty Hash h = Hash.new # an alternative way of doing the same thing h[key] = value # create or overwrite an entry in the Hash -- Posted via http://www.ruby-forum.com/.