John, Well that works perfect now my issue is to understand what you have provided for me. I see that we are creating an array called res however I am not sure what map is doing. I did read the perldoc info on map but I am still confused on how it is being used here. I see from the perldoc that I could use it like this
%register = map {$register($) => $_ @array; print "@array\n"; This would I think create an array based on the values contained in the register hash. But, I would have now way to link them back to the keys from register as now they would be numerically ordered in the array instead of being linked to the hostname key. So I am looking at your example: %actual = map ($actual{$_} eq $register{$_}) This I think says each key eq to the other key value. Next you use a ? mark which I understand means that the previous values are optional, which in this case if the are not equal are they then not included in the $_ variable. But if they are eq then they are included in the $_ value which means they are placed back into the hashes? After this the register hash is sorted but I don't understand why. The next code block iterates through the res array and unless it finds a reference? I did a perldoc on ref and see that it returns a non-empty string if EXPR is a reference. So now I think we created an array of hashes with the @res and map combo, is that correct? Thanks in advance if you decide to try and tackle my confused questions and explain how this works but if you don't want to I understand and still very much appreciate your help. Thanks, -angus #!/usr/bin/perl # use strict; use warnings; system "clear"; my %actual = ( "host1" => "164.72.119.175", "host2" => "164.72.123.43", "host3" => "164.72.45.98", "host4" => "164.72.98.89", "host5" => "164.72.67.123", ); my %register = ( "host1" => "164.72.119.179", "host2" => "164.72.21.43", "host3" => "164.72.45.98", "host4" => "164.72.8.89", "host5" => "164.72.67.123", ); my @res = map { ($actual{$_} eq $register{$_}) ? $_ :[$actual{$_}, $register{$_}] } sort keys %register; foreach my $e(@res) { unless(ref($e)) { print "$e is ok\n"; } else { print "$e differs:actual @{[$e->[0]]} <-> register @{[$e->[1]]}\n"; } } -----Original Message----- From: John Doe [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 01, 2006 2:45 AM To: beginners@perl.org Subject: Re: How to compare hashes to find matching keys with conflicting values. Sorry for another mail, but there are too many typos: > Also untested: > > # If no conflict, value is hostname. > # If conflict, value is arrayref with the two different IPs > # > my @res = map { > ($actual{$_} eq $register{$_}) > ? $_ > : [$actual{$_}, $register{$_}] > > } sort keys %register; > > foreach my $e (@res) { > if (ref($e)) { This should read unless (ref($e)) { > print "$e is ok\n"; > } > else { > print "$e differs: actual @{[$e->[0]]} <-> register @{[$e->[1]]}\n"; > } > } > > I think this should give you an idea. > To look op any perl funktion, type: up, function > > perldoc -f FUNCTIONNAME > > The man page for operaters: operators Nice day to all :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>