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

use next to skip the print if you match (also look into the qr operator in perlop to make this more efficient):
INPUT: while (<IN>) { for my $match (@list) { next INPUT if /$match/; } print; }
Or join your input together (if it has no metacharacters):
my $re = join "|", @list; while ... { print unless /$re/; }
Update: Also, get in the habit of using strict, it may seem like a hassle at first, but makes things more maintainable in the long run.

Replies are listed 'Best First'.
Re^2: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by tadman (Prior) on Jul 09, 2001 at 23:01 UTC
    To be more idiomatic, you should ensure that your @list doesn't contain anything that will get the regex bent out of shape. A simple application of quotemeta will help set things straight:
    my $re = join ("|", map {quotemeta} @list); while (...) { next if /$re/; print; }
    I'm not a huge fan of the 'next LABEL' command. It's too much like 'goto', which is one of those things that shouldn't be shown in public.
      I don't think the purported similarity to goto is a good reason to not use Perl's loop control facilities. OK, the construct is abusable (what construct is not?), but when used appropriately I think that it clarifies things immensely.

      FWIW the following article on Loop Exits and Structured Programming helped shaped my thinking on this.

        I agree. Consider the alternative (warning: marginally yucky code ahead):
        while (<INPUT>) { my $skip; for my $match (@list) { $skip = 1, last if /$match/; } next if $skip; print; }