Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I've noticed there has been a number of articles quite recently that provide help related to what I am doing, but I can't find an answer to solve this problem.# compare each row in the first set of data to every row # in the second set of data. If it does not occur, then # they are different, so print. for my $a ( @ds1_rows ) { my $record1 = "@$a"; my $bool = ''; for $aref ( @ds2_rows ) { my $record2 = "@$a"; $found = $record1 eq $record2; $bool = $found; # set bool vari +able to value of found last if $found; } # if the boolean variable is equal to nothing, the for + loop was # not exited prematurely, thus no record was found mat +ching. if ($bool eq '') { $record_count++; } } # assign field names to values for each record that # is found to be different for (my $x = 0; $x < $record_count; $x++) { for (my $y = 0; $y < $field_count; $y++) { print $column_names[$y] . ": " . $ds1_rows[$x][$y] + . "\n" unless $found; } }
The code above looks at database records stored in arrays (hence array of arrays) and compares one record at a time to all records in a second set to see if there's a match. If there isn't, then it's a unique record and the values of that record must be printed out with field names as a labels.
@ds1_rows and @ds2_rows are arrays of records of values. The number of record values in each record in each set is the same, however the number of records can vary. @column_names is a list of field names that match the number of values.
At the moment I think I can see if a record matches. I can also record the number of non-matches. I can print the column name as a label next to record values, however the records don't represent those that do not exist but are the records first in the array.
Please excuse the fact my code isn't as concise as it probably can be, i'm fairly new to programming and Perl so i've only used what I know and understand.
Cheers for any help that is given, Steve.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing the values of unique database records from comparing arrays of records
by punkish (Priest) on Mar 12, 2005 at 05:29 UTC | |
by Anonymous Monk on Mar 12, 2005 at 05:53 UTC | |
|
Re: Printing the values of unique database records from comparing arrays of records
by Popcorn Dave (Abbot) on Mar 12, 2005 at 03:29 UTC | |
|
Re: Printing the values of unique database records from comparing arrays of records
by TedPride (Priest) on Mar 12, 2005 at 08:52 UTC |