Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Help with outfile.write(line) unless line =~ search_text

Reply
Thread Tools

Help with outfile.write(line) unless line =~ search_text

 
 
Bob Hatch
Guest
Posts: n/a
 
      02-02-2011
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
pat eyler
Guest
Posts: n/a
 
      02-02-2011
try if instead of unless

http://en.wikibooks.org/wiki/Ruby_Pr...rol_Structures

On Wed, Feb 2, 2011 at 11:51 AM, Bob Hatch <(E-Mail Removed)> 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 =3D~ search_text
>
> --
> Posted via http://www.ruby-forum.com/.
>
>




--=20
thanks,
-pate
-------------------------
=A0Don't judge those who choose to sin differently than you do

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      02-02-2011
On 2/2/2011 1:08 PM, pat eyler wrote:
> On Wed, Feb 2, 2011 at 11:51 AM, Bob Hatch <(E-Mail Removed)> 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_Pr...rol_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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ATI card will not sense older tv as sec. display unless VCR connected, help! causewayclubhouse@hotmail.com DVD Video 2 12-18-2005 04:33 PM
Unless unless Gábor SEBESTYÉN Ruby 3 06-17-2005 08:54 AM
HELP - select all checkbox javascript works fine.. unless there is only one checkbox. Michael Champagne Javascript 4 04-20-2004 01:40 AM
Regex problem, match if line contains <a>, unless it also contains <b> James Dyer Perl 5 02-20-2004 12:29 PM
fscanf or fgets still misses last line unless there is a newline Charles Erwin C Programming 4 10-06-2003 08:12 PM



Advertisments