Jay,

Here's my solution. It doesn't use File::Slurp, as Dan suggested, but it 
does what you want it to do. I think that David's point is a good one ... 
if you don't need to preserve order, you can just use a hash. This method 
will preserve the order of the second file.

Pete

#!/usr/bin/perl -w

use strict;

my $file1='one'; my $file2='two'; my $file3='three';

my %domain;

# Load $file1 into a hash
open INFILE, $file1 or die "Can't open $file1: $!";
while (<INFILE>) {
    chomp;
    next if ($_!~/\S/);
    $domain{$_}=1;
}
close INFILE;

# Now read in $file2 and spit the results into $file3,
# prepending a # if the domain was in $file1
open INFILE, $file2 or die "Can't open $file2: $!";
open OUTFILE, ">$file3" or die "Can't open $file3: $!";
while (<INFILE>) {
    chomp;
    print OUTFILE '#' if (defined $domain{$_});
    print OUTFILE "$_\n";
}
close INFILE;
close OUTFILE;

Mar 11, 2003 at 8:40am from Jay Kidd:

JK> I need help trying to figure out what I'm doing wrong.
JK> I'm working with 2 seperate text files both of which
JK> contain domain names.  What I'm attempting to do is
JK> read the first file of domains and run a search based
JK> on the contents of that file against the second file
JK> of domains.  Then open a completely new file writing
JK> the contents of the second file with the exception of
JK> the domains from the first file will be commented out.

-- 
http://emerson.wss.yale.edu/perl
Pete Emerson
WSS AM&T Yale University



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to