in reply to Re: comparing 2 files problem
in thread comparing 2 files problem
# A version that also checks for lines in file2 that are not in file1: open(FILE1, '<file1.txt') or die("Cannot open first file: $!.\n"); open(FILE2, '<file2.txt') or die("Cannot open second file: $!.\n"); %file1 = map { $_ => 1 } <FILE1>; %file2 = map { $_ => 1 } <FILE2>; foreach (keys(%file1)) { if ($file2{$_}) { print("Found in both files: $_"); } else { print("Found only in first file: $_"); } } foreach (keys(%file2)) { unless ($file1{$_}) { print("Found only in second file: $_"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: comparing 2 files problem
by ikegami (Patriarch) on Sep 07, 2004 at 18:54 UTC |