2009年8月8日 星期六

Perl : To compare two files and print differences between them

#!/usr/bin/perl -W

open F1, "< FileA.txt";
open F2, "< FileB.txt";

my %hash1;
my %hash2;

while () { $hash1{$_} = 1; }
while () { $hash2{$_} = 1; }

print "words are in FileA but not in FileB are:\n";
foreach (keys %hash1) { print if !defined($hash2{$_}); }

print "words are in FileB but not in FileA are:\n";
foreach (keys %hash2) { print if !defined($hash1{$_}); }

close F1;
close F2;

沒有留言:

張貼留言