in reply to Filtering Source Text File with 2nd Text File of Terms
Your main problem is when you check to see if the source matches any of the terms, you're only checking the last term in the file.
You're also trying to print a match with the $1 but that's not really what you want.
Beyond that, is there a particular reason you're choosing to use hashes instead of arrays? I would think arrays are more what you want.
# Building the array of terms: my @terms = (); while (my $term = <F1>) { chomp $term; push @terms, $term; }
This way, when you are checking each term against the source, you just need to do this:
# Printing sources that do not match of of the terms: while (my $source = <F2>) { chomp $source; print "$source\n" unless grep { $source =~ /$_/ } @terms; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Filtering Source Text File with 2nd Text File of Terms
by jwkrahn (Abbot) on Apr 03, 2012 at 05:25 UTC | |
by Riales (Hermit) on Apr 03, 2012 at 17:29 UTC | |
by Loops303 (Novice) on Apr 04, 2012 at 04:31 UTC | |
Re^2: Filtering Source Text File with 2nd Text File of Terms
by Loops303 (Novice) on Apr 04, 2012 at 04:33 UTC |
In Section
Seekers of Perl Wisdom