[EMAIL PROTECTED] wrote:
> 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',
        The thing you do is define the hash and provide a counter as an 
element, so by going through the hash you know whether there is more than one 
per either machine or IP.
        Something like:

        $machines{$wrkkey}[0]   # equal counter
        $machines{$wrkkey}[1]   .= $ipaddrr . q[;] ;    #now you have the 
ipaddr as ; separated list and  can either print spaced across or down ot 
whatever.

        Can do the same for the ipaddr and machines.

        Now you can loop through either hash:

        foreach my $machinekey (sort keys %machines ) {
                next if ( $machines{machinekey }[0] < 2 );
                # now can print out or whatver 
       }
        duplicate the code for the Ipaddr sort and print

Wags ;) 
> 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


**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


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

Reply via email to