in reply to Matching and removing a line from a file

split (/, /,$exclude) ^ | missing

I'm assuming $exclude comes from a file or something? If not, the following would be better than creating a string and splitting it:

my @excludes = ( $input{'FName'}, $input{'LName'}, $input{'county'} );

Also,
/$entry/
should be
/^\Q$entry\E\z/
or
$_ eq $entry
\Q..\E convert the text to a regexp pattern. ^..\z makes sure $entry is not just part of the $_.

Replies are listed 'Best First'.
Re^2: Matching and removing a line from a file
by AnomalousMonk (Archbishop) on Dec 10, 2008 at 03:57 UTC
    /^\Q$entry\E\z/
    If the entry field for which a record is to be excluded is anchored to the start and end of the string against which it is matching (so that the match is the same as testing for string equality), doesn't that mean that no record will ever match (and so no record will ever be excluded) because no exclusion field will ever match the entire record?

    Also, because the exclusion fields are never paired to any specific fields of the record in the code of the OP, if one was seeking to exclude Jim Jones of Dade county, would not Jim Dade of Jones county (or, indeed, any record having 'Jim', 'Dade' or 'Jones' in any field) also be excluded?

      Oops, I was rushed when I wrote that.

      While $_ eq $entry should still be used, it should be after extracting the fields.

      while (<>) { my @fields = split /,/; # Text::CSV_XS would be better. next if $field[0] eq $input{FName} || $field[1] eq $input{LName} || $field[3] eq $input{county}; print; }
      or
      while (<>) { my @fields = split /,/; # Text::CSV_XS would be better. next if $field[0] eq $input{FName} && $field[1] eq $input{LName} && $field[3] eq $input{county}; print; }

      depending on what the OP wants.