<?xml version="1.0" encoding="windows-1252"?>
<node id="541598" title="Compare Values in HoH" created="2006-04-06 04:38:44" updated="2006-04-06 00:38:44">
<type id="115">
perlquestion</type>
<author id="180139">
AcidHawk</author>
<data>
<field name="doctext">
Hi,  I have 2 csv files, File1 look as follows&lt;p&gt;
1141286452,ServerA,Disk Full,Arb data,other,stuff&lt;br&gt;
1141286737,ServerB,Net Down,Arb data,other,stuff&lt;br&gt;
1141286737,ServerC,Disk Full,Arb data,other,stuff&lt;p&gt;
and File2 like so&lt;p&gt;
1141286737,ServerB,Net Down&lt;br&gt;
1141286780,ServerD,Bit  Bucket Missing&lt;br&gt;&lt;p&gt;
I read them into 2 seperate hashes. (In the example code I have just hardcoded the hashes.)  Firstly, I need each line of the file to appear in the hash, 
and none of the fields contain UNIQUE data, hence the index (or KEY of Ahash and Bhash) I create ie (1,2,3 etc which relates to line numbers).
The real data is held in the value of Ahash and Bhash as another hash.  Looking at the example code may help with the explanation.&lt;p&gt;
What I want to do is check if a VALUE in Ahash is also in Bhash (or a line in File1 is also in File2).  So here is what I have that works on small hashes...&lt;p&gt;
&lt;code&gt;
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %Ahash = (
	1 =&gt; { 	'Epoch' =&gt; 1234567,
			'Node'	=&gt; "ServerA",
			'Event'	=&gt; "Disk Full",
			'other' =&gt; "Arb data", },
	2 =&gt; { 	'Epoch' =&gt; 1234570,
			'Node'	=&gt; "ServerB",
			'Event'	=&gt; "Net Down",
			'other' =&gt; "Arb data", },
	3 =&gt; { 	'Epoch' =&gt; 1234580,
			'Node'	=&gt; "ServerC",
			'Event'	=&gt; "Screen Stolen",
			'other' =&gt; "Arb data", },
			);
			
my %Bhash = (
	1 =&gt; { 	'Epoch' =&gt; 1234530,
			'Node'	=&gt; "ServerD",
			'Event'	=&gt; "Bit  Bucket Missing",},
	2 =&gt; { 	'Epoch' =&gt; 1234567,
			'Node'	=&gt; "ServerA",
			'Event'	=&gt; "Disk Full",},
			);
			
#print Dumper (%Ahash);
#print "===================================\n";
#print Dumper (%Bhash);
			
while ( (my $Akey, my $Avalue) = each %Ahash) {
	while ( (my $Bkey, my $Bvalue) = each %Bhash) {
		if (
			$$Bvalue{'Epoch'} eq $$Avalue{'Epoch'} &amp;&amp;
			$$Bvalue{'Node'} eq $$Avalue{'Node'} &amp;&amp;
			$$Bvalue{'Event'} eq $$Avalue{'Event'}
		) {
			print "&gt;&gt;&gt;&gt;&gt;&gt;&gt;MATCHED\n";
			print "Ahash =&gt; " . Dumper($Avalue);
			print "Bhash =&gt; " . Dumper($Bvalue);
			print "MATCHED&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\n";
		}
		else {
			print "NOT MATCHED\n";
		}
	}
}
&lt;/code&gt;
&lt;p&gt;
This does not scale well as you can see that each value in Ahash is checked agains each value in Bhash.  Is there a better way to compare values in hashes that are hashes?

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-180139"&gt;
-----&lt;BR&gt;
&lt;i&gt;Of all the things I've lost in my life, its my mind I miss the most.&lt;/i&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
