On Wed, Nov 19, 2003 at 10:02:34PM -0000, Peter Scott <[EMAIL PROTECTED]> wrote:
> Problem: multiple files containing essentially identical
> reports which I want to compare. 'diff' isn't the answer;
> in this case each file contains a bunch of stuff I'm not
> interested in that can change; I just want to get an element
> of each one and say which of the other files don't contain that
> element.
I would do it more like this:
use warnings;
use strict;
sub check_re { eval { qr/${\shift}/ } || return }
my $regex = "(".shift().")";
check_re($regex) or die "invalid regex: $regex\n";
my %files;
my %data;
while (<>) {
++$files{$ARGV};
next unless /$regex/;
++$data{$+}{$ARGV};
}
my @files = sort keys %files;
for my $value (sort keys %data) {
if (keys %{$data{$value}} != @files) {
printf "In %s but not in %s: %s\n",
join(", ",keys %{$data{$value}}),
join(", ",grep !exists $data{$value}{$_}, @files),
$value;
}
}