Sam Roberts wrote: > On Wed, Apr 12, 2006 at 08:58:17PM +0900, Peter Bailey wrote: >> >> I tried the following in IRB, but I get the syntax error shown below. >> >> File.open("psout.txt", "w") do |output| >> File.foreach("test1.ps") do |line| >> line.sub!(/\%\%Pages: ([0-9]{1,5})/"Pages: \1"/) > > Other people commented on the regex > >> output << line > > For efficiency, you can do: > > if(line =~ /%%Pages: (\d+)/) > output << $1 > break > end > > YMMV, but stopping processing the file as soon as you've found what you > want is faster. > > Sam Thanks, Sam. So, is doing your "if(line . . ." suggestion quicker, do you think, than doing a .scan? Because I'm dealing with sometimes huge files, whatever's quickest is good. By the way, what do you mean with "YMMV?" -- Posted via http://www.ruby-forum.com/.