From: Ross Bamford Date: 2006-04-12T23:59:22+09:00 Subject: Re: Simple substitutions On Wed, 2006-04-12 at 22:35 +0900, Peter Bailey wrote: > Ross Bamford wrote: > > If you do choose to read the whole thing in at once, one way to achieve > > that might be: > > > > pages = nil > > File.read('test1.ps').scan(/\%\%Pages: ([0-9]{1,5})/) do > > pages = $1 > > break > > end > > > > if pages > > File.open("psout.txt", "w") { |out| out << "Pages: #{pages}" } > > end > > > Aha. I didn't know about "scan." Just the word alone makes sense for > what I want. And, yes, I found it in the Big Book, on page 617. > > What does the "break" do, Ross? Is it just telling RUBY to stop if it's > found what it was scanning for? Yes - you can find a bit about it near the end of this page: http://www.rubycentral.com/book/tut_expressions.html Looking at that again, though, I can't imagine why I didn't just write: if File.read('test1.ps') =~ /\%\%Pages: ([0-9]{1,5})/ pages = $1 end For just a single match. -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk