Gossamer Forum
Home : General : Perl Programming :

compare two text files

Quote Reply
compare two text files
list.txt (contains 3 enteries)
######
file1.html
file3.html
file2.html
######

data.txt (contains 2 enteries)
######
file3.html
file1.html
######


open (LIST, "list.txt");
@list = <LIST>;
chomp @list;
open (DATA, "data.txt");
@data = <DATA>;
chomp @data;
foreach $file (@list) {
foreach $line (@data) {
if ($file eq $line) {
print "$file exists\n";
}
}
}

############
It gives output:
file1.html exists
file3.html exists

My question how to Add file2.html DOESN't exist in the output.

The script is matching the files and reporting the files which exists, how can I get the files which are not matching?

TIA,

Zeshan.
Subject Author Views Date
Thread compare two text files zeshan 6943 Jul 11, 2003, 6:42 PM
Thread Re: [zeshan] compare two text files
Andy 6843 Jul 12, 2003, 1:37 AM
Thread Re: [Andy] compare two text files
Paul 6896 Jul 12, 2003, 3:00 AM
Thread Re: [Paul] compare two text files
Andy 6831 Jul 12, 2003, 3:12 AM
Thread Re: [Andy] compare two text files
zeshan 6852 Jul 12, 2003, 2:43 PM
Thread Re: [zeshan] compare two text files
Andy 6837 Jul 13, 2003, 2:27 AM
Post Re: [Andy] compare two text files
zeshan 6800 Jul 13, 2003, 1:12 PM