# 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
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.#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;
Hope all this helps.
In reply to Re: Printing the values of unique database records from comparing arrays of records
by punkish
in thread Printing the values of unique database records from comparing arrays of records
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |