From: Robert Klemme Date: 2006-03-12T23:38:44+09:00 Subject: Re: Help me understand why the Ruby block is slower than wit Alan Burch wrote: > Others: > Any input as to why it runs slower inside the file block? Have I > overlooked something simple? I'm not sure whether this question has been answered yet. It's probably slower because you do not close the file handle in your first version (more precisely, you close it only if there is an error, which doesn't happen the way you did it). f = File.open("./words") begin ... rescue EOFError f.close end If you wanted it to be equivalent with the block version "f.close" would have to go to an "ensure" section. Generally he block form is preferred because it closes the file handle. Your first version didn't do that. This is probably what I'd do IO.foreach("wordlist") do |line| line.scan /\b\w{11}\b/ do |word| puts word unless /(.).*\1/ =~ word end end The first regexp finds all words with length 11 and the second excludes all words that contain repeting characters. HTH Kind regards robert