Quick and dirty: Make two hashes of arrays, one indexed by IP address,
and one by computername.
#################
#NOTE: Not tested
use strict;
use warnings;
my %byName;
my %byIP;
open(INFILE,"<","myfile.txt") or die("Couldn't open 'myfile.txt' for
reading!\n");
while(<INFILE>){
chomp $_;
if($_ =~ /^\s+(\S+)\s+(\S+)/){
push @{$byName{$1}},$2;
push @{$byIP{$2}},$1;
}
}
my @findName = qw(m001ws m004ws m003ws);
my @findIP = qw(192.168.20.4 192.168.20.10 192.168.20.9);
#Find by name
foreach my $findName(sort @findNames){
print "$findName\n";
foreach my $IP(sort @{$byName{m002ws}}){
print "\tIP => $IP\n";
}
}
#Find by IP
foreach my $findIP(sort @findIPs){
print "$findIP\n";
foreach my $name(sort @{$byIP{m002ws}}){
print "\tName => $name\n";
}
}
################
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
King, Dan
Sent: Monday, May 08, 2006 11:23 AM
To: [email protected]
Subject: Finding partly duplicated records
I am at my wits end on this question. I feel like the answer is
probably simple but it has me beat.
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.
For example:
m001ws 192.168.20.2
m002ws 192.168.20.4
m003ws 192.168.20.6
m003ws 192.168.20.10
m004ws 192.168.20.9
m005ws 192.168.20.20
m006ws 192.168.20.12
m009ws 192.168.20.12
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
I also have a longer record consisting of about 9 fields where I want
to know if there is a duplication within one of the fields. For example
any time a userid appeared in more than one record.
I was thinking that these are basically the same problem but I can't
seem to find any examples on the web. I would appreciate any help.
By the way, in the real problems I am looking at several thousand
'records' and I need to run these reports once a day.
Dan
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs