From: Robert Dober Date: 2007-07-10T18:47:30+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... On 7/10/07, Martin DeMello wrote: > On 7/10/07, John Carter wrote: > > 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 > I am with James do not slurp in the whole string it just does not make sense to me. I would feel very uneasy using regexps on large strings even if right now there seems no backtracking issues to be present, but code evolves sometimes ;) > ARGF.read.scan( %r{GET /ongoing/When/\d{3}x/(\d#{4}/\d#{4}/[^ .]+) }) do |match| Nope Martin read the original code again!! All the / and \ ;). I was about to fall into the same trap. As a matter of fact I miss all beauty in that code :( The regexp is just ugly, some ideas for cosmetic surgery ;) def dig_dirs *args Regexp.new args.map{|n| "\d" * n}.join("/") end puts ARGF.map { |line| line =~ %r{ GET /ongoing/When/\d{3}x/(#{dig_dirs 4, 2, 2}/[^ .])} $1 }.compact But beauty lies to everybody (or was that "in the eyes of the beholder"? ). Cheers Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck