From: Robert Klemme Date: 2007-07-19T21:30:35+09:00 Subject: Re: identify and extract positions from a string - how to? 2007/7/19, F. Senault : > Le 19 juillet � 13:16, Marc Hoeppner a �crit : > > > and uses it in the extraction method > > > > file.readlines each do |l| > > puts string[l] > > end > > The others solutions in the thread are the ones to use, but I feel the > need to suggest the very dirty / insecure / bad one : > > File(filepath).readlines.each do |l| > puts string[eval(l)] > end > > Don't try this at home, etc... :) > > (But, in a controlled environment, it may be useful since it allows for > all the variations that can be evaluated in one line of ruby code...) A safer variant: file.each do |line| if /^(\d+)\.\.(\d+)$/ =~ line puts string[ $1.to_i .. $2.to_i ] end end Note, that file.each is more efficient than file.readlines.each because it does not need to read the whole file into memory. Kind regards robert