Do you know how to get the count of an array?
Using my example, since you know that you can cycle through the keys of
%findName and %findIP, and you know that you can access each array by
dereferencing it like so: @{$findName{$name}}, you should be able to
find the count of @{$findName{$name}}. If it is more than 1, you've got
a duplicate. You can either do something with it as you find it or push
the key onto another array to be used later.
Does that help?
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
King, Dan
Sent: Monday, May 08, 2006 2:10 PM
To: [email protected]
Subject: RE: Finding partly duplicated records
Thanks for the replies so far. I am going to respond to this one for all
of them up to now.
This approach is very good for the problem with only two data elements
on a line, but it
seems to require that I know the duplicate entries when I write the
code.
I can only guess that the posters left finding the duplicates as an
'exercise for the reader',
not realizing that at this point, this reader's brain is totally fubar.
When I use data::dumper I find this (only for the first HOA (that is
right isn't it, HOA?))
$VAR1 = 'm003ws';
$VAR2 = [
'192.168.20.6',
'192.168.20.10'
];
$VAR3 = 'm009ws';
$VAR4 = [
'192.168.20.12'
];
More data left off for the sake of the poor, suffering electrons.
Once I have the data structure I just need to print anything that has
more than one value in the array.
I am going back to the O'Reilly books to try to figure it out.
More to come, I am sure.
Thanks,
Dan
-----Original Message-----
From: [mailto:[EMAIL PROTECTED]
Sent: Monday, May 08, 2006 15:42
To: [email protected]; King, Dan
Subject: Re: Finding partly duplicated records
How about something like this:
my %machines = (); # List of machines with their IPs my %ipaddrss = ();
# List of IPs with their machines
# We assume the db is a flat file and that the file # is already opened.
We also assume that the fields # are separated by whitespace (as per
your example).
while (my $line = <FH>) {
chomp($line);
# Split the record by whitespace
my ($host, $ip) = split(/\s+/, $line);
# Save the ip in the machine's record
if (exists $machines{$host}) {
push(@{ $machines{$host} }, $ip);
} else {
$machines{$host} = [ $ip ];
}
# Save the host in the ip's record
if (exists $ipaddrss{$ip}) {
push(@{ $ipaddrss{$ip} }, $host);
} else {
$ipaddrss{$ip} = [ $host ];
}
}
At the end you'll have 2 hashes, one containing a list of machines and
the IPs that belong to each one, and the other containing a list of IPs
and the machines they belong to. I am assuming that you want to find
the duplicate records and store them to use them for something. If you
just want to count how many times they occur then its different.
To access the stored duplicates, just do something like this:
# 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;
}
# Output all the hosts belonging to $ip
my $ip = '192.168.20.2';
foreach my $host ( @{ $ipaddrss{$ip} }) {
print $host;
}
I hope this helps!
-dZ.
_______________________________________________
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