At 02:23 PM 5/8/2006 -0400, King, Dan wrote:
>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.  
>I want to find m003ws with its two IP addresses 
>    m003ws     192.168.20.6
>    m003ws     192.168.20.10
>
>and 192.168.20.12 with its two machines.
>    m006ws     192.168.20.12
>    m009ws     192.168.20.12

Here's my 2.2274 yen.

foreach $line (@lines) {
        my ($name, $ip) =~ m/^\s*(\S+)\s+(\S+)\s*$/;
        $namehash{$name}{$ip}++;
        $iphash{$ip}{$name}++;
}
# duplicates validation
foreach $name (keys %namehash) {
        foreach $ip (keys %$namehash{$name}) {
                if ($namehash{$name}{$ip} > 1) {
                        print "Warning: $name\t$ip occurs
$namehash{$name}{$ip} times\n";
                }
        }
}
foreach $ip (keys %iphash) {
        foreach $name (keys %$iphash{$ip}) {
                if ($iphash{$ip}{$name} > 1) {
                        print "Warning: $name\t$ip occurs
$iphash{$ip}{$name} times\n";
                }
        }
}

print "Enter search term: " and $wanted = <STDIN>;
chomp $wanted;

if ($namehash{$wanted}) {
        print "That name appears with the following IP addresses:\n";
        #foreach $key (keys %$namehash{$wanted}) {
        #        print "$wanted\t$key\n";
        #}  # or:
        print join "\n", map {"$wanted\t$_" } keys %$namehash{$wanted};
}
if ($iphash{$wanted}) {
        print "That IP appears with the following names:\n";
        #foreach $key (keys %$iphash{$wanted}) {
        #        print "$key\t$wanted\n";
        #}  # or:
       print join "\n", map {"$_\t$wanted" } keys %$iphash{$wanted};
}





--
REMEMBER THE WORLD TRADE CENTER         ---=< WTC 911 >=--
"...ne cede malis"

00000100

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

Reply via email to