Hi, I am pretty much a newbie to perl. Here is my question...
I understand that `grep xyz anyfile` can be expressed as
while <anyfile> { if (/xyz/) { print $_; } }
But how would I approximate grep -v in perl?
When I use (!/xyz) I am getting some strange results, namely every line of the file is being displayed with the one line that does not match "xyz" being displayed twice at the end of the output. I should also mention that I am using a foreach $i (@list) where @list = qw (leroy brown). I am sure that I am not using the $_ variable correctly but I don't know exactly what it is that I am doing wrong.
SCRIPT: #!/usr/bin/perl -w @list = qw (leroy brown); $log="/home/psmith/logfile"; open IN (<$log); while <IN> { foreach $i (@list){ if (!/$i/) { print $_; } } } OUTPUT: the quick brown fox jumped over the lazy dogs leroy black the badest man in the whole damn town live long and prosper live long and prosper

Any help would be appreciated!

Thanks


Edit 2001-07-09 ar0n -- New title


In reply to Unix 'grep -v' equivalency in Perl (was: Perl Regex Question) by quasimojo321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.