From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-05-08T04:10:04+09:00 Subject: [ruby-talk:14796] Re: bizarre eval resource problem solved In article , Dave Thomas wrote: >"Guy N. Hurst" writes: > >> >>> >> To determine pass/fail, there is a string in the >> file (which is the srchStr in the example above) that is an expression >> composed of regex's and logical operators, like: >> "!(/Error Count = [1-9]/ || /Abort/ || /[1-9] error/ || /fatal/)" >> <<< >> >> >> So you see, the string is in the file. Since it is pre-existing, >> he can't be told to do it otherwise. This is a legacy code issue ;-) > >No, but we can suggest he do it differently :) Please do: anything you can suggest to speed this thing up would be good! > >I haven't performance tested this, but it does avoid the eval each >time around the loop. It uses the proof-of-concept eregex package >distributed with the Ruby source: > > require "eregex" > > pat = "/a/ | /b/" > > matcher = eval "proc {|str| str =~ " + pat + "}" > > while line = gets > if matcher.call line > puts line > end > end Dave, Can you explain what the 'eregex' package does? In your code above, does it mean that any regex's defined after the 'require "eregex"' are eregex objects or does it mean that after the require, regex's are evaluated differently somehow? Anyway, I tried it, and it kindof, sorta works - and when it does work it is indeed much faster. The problem is that if I have something like: !(/Error/ || /Abort/) it doesn't work (doesn't like the '!' and the parens. It will work for something like: '/Completed Successfully/ || /Finished No Errors/', but not if it has parens around it, like: '(/Completed Succesfully/ || /Finished, No Errors/')' Phil