In article <Pine.LNX.4.30.0104251834140.9817-100000 / candle.superlink.net>,
David Alan Black  <dblack / candle.superlink.net> wrote:
>On Thu, 26 Apr 2001, Phil Tomson wrote:
>
>> $expression = "!(/Error/ || /Abort/ || /[1-9] error/ || /fatal/)"
>> #actually $expression was read from one of many (thousands) of files
>> open(RPT,"reportfile) or die ;
>                      ^ you forgot the closing "  :-)
>
>> while (<RPT>) {
>>    if(eval "$expression") {
>>       $found = 1;
>>       #other stuff....
>>    }
>> }
>>
>> So 'eval "$expression"' returns a true value if $expression evaluates to
>> true (in the Perl sense of truth).
>>
>> Now, I'm finding that something like:
>>
>> if (line =~ !(/Error/ || /Abort/ || /[1-9] error/ || /fatal/) )
>>
>> just isn't going to work in Ruby for various reasons.  Technically, the
>> strings in $expression (above) are not regular expressions, they are
>> formulas that contain regular expressions.
>
>
>You can use $_, which IO#gets will assign to automatically:
>
>   expression = "!(/Error/ || /Abort/ || /[1-9] error/ || /fatal/)"
>   fh = File.open "phil.dat"   # see below
>
>   while fh.gets do
>     puts $_ unless eval expression  # or whatever
>   end
>
>
>phil.dat:
>
>   This line contains Abort.
>   This one doesn't.
>   This one says Error.
>
>
>Output:
>
>   This line contains Abort.
>   This one says Error.
>
>

Thanks, David.  I thought I tried something very similar, but it still 
used '=~' which wasn't working out since it wants to match a regex not an 
expression.  Your solution works fine and saves me a lot of trouble.

Phil