Just for practice, here's what I was thinking: if you evaluate an array
in scalar context, you get the number of elements, so the below should
work. If for some reason it doesn't work, try 'scalar(@array) > 1'
instead of '@array > 1'.
#################
#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;
}
}
#Find duplicate names
foreach my $name(sort keys %byName){
#Check if there is more than one entry
if(@{$byName{$name}} > 1){
print "MULTIPLE IPs FOR $name\n";
#Cycle through the entries and print them
foreach my $IP(@{$byName{$name}}){
print "\tIP => $IP\n";
}
}
}
print "\n----------------\n\n";
#Find duplicate addresses
foreach my $IP(sort keys %byIP){
#Check if there is more than one entry
if(@{$byIP{$IP}} > 1){
print "MULTIPLE NAMES FOR $IP\n";
#Cycle through the entries and print them
foreach my $name(@{$byIP{$IP}}){
print "\tName => $name\n";
}
}
}
################
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Timothy Johnson
Sent: Monday, May 08, 2006 3:04 PM
To: King, Dan; [email protected]
Subject: RE: Finding partly duplicated records
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?
<snip>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs