From: Brian Candler Date: 2010-09-15T04:20:05+09:00 Subject: Re: beginner's q about eval and/or code blocks Jeff Myers wrote: > This ruby program successfully prints all 5-letter words starting with > 'j' > (in a text file containing all current U.S. English Scrabble words). > > fp = File.open('C:\Documents and Settings\User\twl06FromMac.txt') > fp.each do |line| > puts line if line =~ /^j....$/ > end > > I would like to allow the user to enter the regex rather than have it > hard-coded as above. I've tried to get eval to work after building a > string to pass it. No luck so far. Try something like: str = $stdin.gets.chomp re = Regexp.new(str) ... puts line if line =~ re -- Posted via http://www.ruby-forum.com/.