Here is where I begin. I am reading arrays from a database one at a time using a while loop. I want to pick up on elements from the database that are duplicates (on certain fields). I want to keep only the items that are unique on these fields. Then I want to print out the data I have kept in a certain way. I created the code I thought would do it, but it gives me everything including items which are duplicates on the field. I've been searching and searching and I can't figure it out, I'm thinking, as a perl noob, I am missing something simple. Code is as follows:
my @uniques = ();
my $output;
while (my @itemArray = $sth->fetchrow_array() ) {
my $duplicateFlag = 0;
foreach (@uniques){
if( ($itemArray[3] eq "$_->[3]") and ($itemArray[4] eq "$_->[4]")
and ($itemArray[5] eq "$_->[5]" ) and ($itemArray[6] eq "$_->[6]" )
and ($itemArray[7] eq "$_->[7]" ) and ($itemArray[8] == "$_->[8]" ) ){
$duplicateFlag = 1;
}
}
if( $duplicateflag == 0){
$refToAdd = \@itemArray;
push(@uniques, $refToAdd);
$output .= "$itemArray[3]" . "\t$itemArray[8]" . "\t$itemArray[5]" . "\t$itemArray[7]\n";
}
}
print $output