On Wed, 16 May 2001 08:18:03 -0400, bobbys wrote:
>I'm sorry, but I guess this question isn't specific to MacPerl, but here goes:
>
>I have two text files, both with lists. One is called "master" and
>the other is "removes".
>
>"removes" contains a list of items that I want removed from the
>"master" file (there's one string on each line).
>
>What's the best way to strip out all the desired items from the master file?
Load the "removes" file into a hash (as the hash keys). Do a grep() on
the master file for those entries that aren't in the hash.
#! perl -i.bak
@ARGV = 'master';
open REMOVE, 'remove' or die "Cannot open file: $!";
while(<REMOVE>) {
chomp;
$remove{$_} = 1;
}
# Ready? Go!
$\ = "\n";
while(<>) {
chomp;
print unless $remove{$_};
}
--
Bart.