From: Jeremy Bopp Date: 2011-02-03T04:41:50+09:00 Subject: Re: Help with outfile.write(line) unless line =~ search_text On 2/2/2011 1:08 PM, pat eyler wrote: > On Wed, Feb 2, 2011 at 11:51 AM, Bob Hatch wrote: >> Rather than having the output write the line unless it equals >> search_text, I need it to write when it equals search_text. I know that >> should be easy, but I can't find the syntax. >> >> outfile.write(line) unless line =~ search_text > > try if instead of unless > > http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures Using if instead of unless is definitely clearer here, but you can also negate the match operator by replacing =~ with !~ as follows: outfile.write(line) unless line !~ search_text Double negatives are usually unnecessarily hard to understand at a glance though, so use the if statement instead of unless here. -Jeremy