Hi, If it's not required to have the domain commented out (meaning it can just not be there) then you could do this much more easily with a hash.
If your new file can simply have: rtfm.com readitagain.com Then doing something like this would work well: my %domains = (); open( OLD, "$domainlist" ) || die "Couldn't open $domainlist: $!"; while( <OLD> ) { chomp; $domains{$_} = -1; } close( OLD ); open( NEW, "$hostnames" ) || die "Couldn't open $hostnames: $!"; while( <NEW> ) { chomp; $domains{$_} = 1; } close( NEW ); then loop over %domains, and anytime $domains{$key} == 1, print it out! -------------------------- David Olbersen iGuard Engineer 11415 West Bernardo Court San Diego, CA 92127 1-858-676-2277 x2152 > -----Original Message----- > From: Jay Kidd [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 11, 2003 8:40 AM > To: [EMAIL PROTECTED] > Subject: Search and Replace > > > 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] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]