Hello, I need help trying to figure out what I'm doing wrong. I'm working with 2 seperate text files both of which contain domain names. What I'm attempting to do is read the first file of domains and run a search based on the contents of that file against the second file of domains. Then open a completely new file writing the contents of the second file with the exception of the domains from the first file will be commented out.
Here's an example: File 1: dummy.com stupid.com idiot.com newbie.com File 2: rtfm.com readitagain.com dummy.com stupid.com idiot.com newbie.com New File: rtfm.com readitagain.com #dummy.com #stupid.com #idiot.com #newbie.com With the script that I wrote what happens is it only comments out the last entry from file 1. so when it writes to the new file only (newbie.com) will be commented out: New File With My Script: rtfm.com readitagain.com dummy.com stupid.com idiot.com #newbie.com Anyone know what I'm doing wrong? Here's the script I'm working with: #!/usr/bin/perl -w use strict; my $domainlist = shift || die("You must provide a domain list file."); my $hostnames = "local-host-names"; open(DAT, "<$domainlist") || die("Unable to open '$domainlist'."); while (<DAT>) { chomp; print $_,"\n"; my $cur1 = $_; open (DATA, "<$hostnames"); open (NEWDATA, ">$hostnames.new"); while (<DATA>) { chomp; my $cur2 = $_; my ($data) = $cur2 =~ /($cur1)/is; my $newdata; if ($data) { $newdata = "#" . $cur2; } else { $newdata = $cur2; } print NEWDATA "$newdata\n"; } close DATA; close NEWDATA; } close DAT; I was able to get all domains commented out by putting line in: open (NEWDATA, ">>$hostnames.new"); instead of: open (NEWDATA, ">$hostnames.new"); But it also made duplicate entries in the new text file as well. So for every entry that looked like this: rtfm.com readitagain.com #dummy.com #stupid.com #idiot.com #newbie.com There were 3 more entries that looked like this: rtfm.com readitagain.com dummy.com stupid.com idiot.com newbie.com Any guidance on how to fix this problem would be greatly appreciated... __________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]