On May 8, 2006, at 17:09, King, Dan wrote:

# Output all the IPs belonging to $host
my $host = 'm001ws';                        ##DAN## I don't know the
names of the duplicates.
foreach my $ip ( @{ $machines{$host} }) {
   print $ip;
}


Then I didn't understand your problem. My apologies. I thought you wanted to get all the IPs and Hosts and then go through them to find the duplicates, but if you only want to point out the duplicates, then you can do this to get them:

my @dup_machines = ();

# Get the hosts with more than one IP
foreach my $host (key %machines) {
        # Check if the host has more than one IP
        if (scalar(@{ $machines{ $host } }) > 1) {
                # This host has more than one IP
                # we can save it, but we can also
                # perform any operation on it right now
                push(@dup_machines, $host);

                # Do something else...?
        }
}

my @dup_ips = ();

# And the same thing for the IPs with
# more than one host.
foreach my $ip (key %ipaddrss) {
        # Check if the IP has more than one host
        if (scalar(@{ $ipaddrss{ $ip } }) > 1) {
                # This ip has more than one host
                # we can save it, but we can also
                # perform any operation on it right now
                push(@dup_ips, $ip);

                # Do something else...?
        }
}


Any better now? What we're doing is looping through the list of hosts and IPs extracted from the file and finding those that have duplicates. I am still assuming that you want to keep the values, that is, that you want to keep the ips of the duplicate hosts, and that you want to keep the hosts of the duplicate ips, not just find them. The code would be substantially simpler if all you want to do is find *which* hosts are duplicated, and not care which ips belong to them.

        dZ.


--
// Do something
marypoppins = ( superman + starship ) / god;

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

Reply via email to