in reply to Re: Comparison Of Files
in thread Comparison Of Files

Ok. I stole a lot of the chipmunk's code (because I'm lazy and didn't want to type...). Instead, I trade speed for memory by using one hash for both old & new.

sub compare_sites { my($old, $new) = @_; if (-M $new > -M $old) { ($old, $new) = ($new, $old); } open(OLD, $old) or die "Can't open $old: $!\n"; open(NEW, $new) or die "Can't open $new: $!\n"; my %hash; my $omsk = 1; my $nmsk = 2; while (<OLD>) { chomp; $hash{$_} |= $omsk; } while (<NEW>) { chomp; $hash{$_} |= $nmsk; } close(OLD); close(NEW); for (sort keys %hash) { if ($hash{$_} == 1) { print "$_ went down overnight.\n"; } } for (sort keys %hash) { if ($hash{$_} == 2) { print "$_ went up overnight.\n"; } } } compare_sites("newsite1.txt", "newsite2.txt");
Now you could just go through the hash once and push into arrays as well, but then we might as well use the chipmunk hash. (Dance or Dish?)