in reply to Printing the values of unique database records from comparing arrays of records

The way I understand your problem, you have several errors in your code...
# if @ds1_rows is an AofA holding a dataset, then... for my $a ( @ds1_rows ) { # $record1 is an array, not a scalar... you are deref-ing # an arrayref and assigning it to a scalar, which doesn't # make any sense my $record1 = "@$a"; my $bool = ''; # then, further on... # you are assigning each element to $aref # (where is the 'my'?)... for $aref ( @ds2_rows ) { # and then, not using $aref... # instead, you are using $a again my $record2 = "@$a";

That said, lets ponder over what you mean by "one record at a time to all records in a second set to see if there's a match." Do you mean to compare an entire record, by which you seem to imply an entire row, with each entire row in the second set? I mean, if each row has 10 columns, do all the 10 columns have to be identical to all the 10 columns in another row for the two to be identical? That is a bit confusing.

In any case, you want to compare two arrays (well, AofAs in this case, but still arrays nonetheless) and compute their intersection. From the Cookbook, you get

#Simple solution for union and intersection foreach $e (@a) { $union{$e} = 1 } foreach $e (@b) { if ( $union{$e} ) { $isect{$e} = 1 } $union{$e} = 1; } @union = keys %union; @isect = keys %isect;
Apply the above logic. Or, loop over one array, and for each element, grep through the other array. Check out the usage of grep to search for an value in an array.

Hope all this helps.

--

when small people start casting long shadows, it is time to go to bed

Replies are listed 'Best First'.
Re^2: Printing the values of unique database records from comparing arrays of records
by Anonymous Monk on Mar 12, 2005 at 05:53 UTC
    Yes, I want to compare the whole row. The reason being, each record contains configuration data. While some values may be the same as in another record, others can be different. e.g. ("cpu","intel") and ("cpu","amd"), the cpu values are the same but the processor manufacturers are different. So this is why I want to compare the whole row and output all the record values with labels e.g. Hardware, Manufacturer.