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!)
#!/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);
Thank you.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.