From: Christian Neukirchen Date: 2007-07-21T23:27:07+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... John Carter writes: > For example scanning a log file..... > > EXAMPLE 4-2 . Printing article names > 1 ARGF.each_line do |line| > 2 if line =~ %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) } > 3 puts $1 > 4 end > 5 end > > Since most Linux distro's roll the log files to a reasonable size I would have just gone with... > > ARGF.read.scan( %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }) do |match| > puts $1 > end Kinda late to the party, but I'm amazed noone came up with: ARGF.grep(%r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }) { puts $1 } -- Christian Neukirchen http://chneukirchen.org