Title: RE: Finding partly duplicated records

>
> I have a list of machines and IP addresses.  The combination,
> $machine and $IPAddress is never duplicated in the list.  However,
> $IPAddress may be duplicated and $machine may be duplicated. 
>

You can actually do this in a single pass and a single hash, assuming no hostnames are the same as an IP. Even then, it might work:

### not tested

use strict;
my %hash;

open(INFILE,"<","myfile.txt") or die("Couldn't open 'myfile.txt' for reading : $!\n");

while(<INFILE>)
{
        chomp $_;
        my($hostname,$ip) =~ /^\s+(\S+)\s+(\S+)/);
        $hash{$hostname}{$ip}++;
        $hash{$ip}{$hostname}++;
}


foreach my $key1 (keys %hash)
{
        foreach my $key2 (keys %hash{$key1})
        {
                print "$key1,$key2 duplicated" if ($$key1{$key2} > 1);
        }
}

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to