From: Robert Klemme Date: 2005-11-28T21:47:30+09:00 Subject: Re: from a file to an array of words ngoc wrote: > I want to compare two text(html) files. "diff" command in Linux > compares only by line. > In Ruby, I can use "File.readlines" and "split" later. Is there a > single function(method) to go from a file to an array of words. What is a word in your context? If you want an array of tokens consisting only of word characters you can do words = File.read(file_name).scan(/\w+/) Note though that this is memory intensive for large files. This is a bit more efficient: words = File.open(file_name) do |io| io.inject([]) {|w, line| w.concat( line.scan( /\w+/ ) )} end Kind regards robert