Loops303 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I am a novice at Perl.
I have a SOURCE text file with a list of strings, such as
http://www.google.com
www3.manish.net
www.nov8rix.com
www.thisisannoying.com
and a 2nd text file FILTER TERMS with a list of terms such as
google
manish
www.thisisannoying.com
What I want to do is read the 2nd file and using the list of those terms, to filter out the first file.
The desired end result OUTPUT would be
www.nov8rix.com
It would not write
http://www.google.com --- because it matches the "google"
www3.manish.net --- because it matches the "manish"
www.thisisannoying.com --- because it matches the "www.thisisannoying.com"
Can anyone please help me figure out how to do this?
Here is the code I have thus far (this is the 20th iteration of various attempts, having spent about 5 hours on this already today --- see, I am new at this!)Thank you.#!/usr/bin/perl open (F1, "<filterTerms.txt"); open (F2, "<source.txt"); my %terms = (); my %source = (); while (<F1>) { my $term=$_; chomp ($term); $terms{$term}=$term; } while (<F2>) { my $item=$_; chomp ($item); $source{$item}=$item; foreach (keys %source) { if ($source=~m/($term{$term})/) { #do nothing } else { print $1."\n"; } } } close (F1); close (F2);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filtering Source Text File with 2nd Text File of Terms
by Riales (Hermit) on Apr 02, 2012 at 23:49 UTC | |
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 | |
by Loops303 (Novice) on Apr 04, 2012 at 04:33 UTC | |
|
Re: Filtering Source Text File with 2nd Text File of Terms
by vitoco (Hermit) on Apr 03, 2012 at 17:53 UTC |