Ok ppl,
after some hard work (for me at least!!) that's what I got:

#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use DBD::mysql;
use warnings;

my (
$db_gal,$db_gal2,$db_lab,$tbl_ary_ref_g1,$tbl_ary_ref_g2,$tbl_ary_ref_l1 );

###########################################################################
#Query G1 from the db test_gal, the results are: [alfa , 10] , [beta , 11];
###########################################################################
$db_gal = DBI->connect(
"dbi:mysql:test_gal:localhost:3306","user","password" )
   || die( $DBI::errstr . "\n" );

my $SEL_G1 = "select col1,col2 from GAL";

my $query_handle_gal = $db_gal->prepare($SEL_G1);

$query_handle_gal->execute();
$tbl_ary_ref_g1 = $query_handle_gal->fetchall_arrayref();

############################################################################
#Query L1 from the db test_lab, the results are: [gamma , 12] , [alfa , 10];
############################################################################
$db_lab = DBI->connect(
"dbi:mysql:test_lab:localhost:3306","user","password" )
   || die( $DBI::errstr . "\n" );

my $SEL_L1 = "select * from LAB";

my $query_handle_lab = $db_lab->prepare($SEL_L1);

$query_handle_lab->execute();
$tbl_ary_ref_l1 = $query_handle_lab->fetchall_arrayref();
###########################################################################
#Query G2 from the db test_gal, the results are:(gamma);
###########################################################################
$db_gal2 = DBI->connect(
"dbi:mysql:test_gal:localhost:3306","user","password" )
   || die( $DBI::errstr . "\n" );

my $SEL_G2 = "select * from GAL2";

my $query_handle_gal2 = $db_gal2->prepare($SEL_G2);

$query_handle_gal2->execute();
$tbl_ary_ref_g2 = $query_handle_gal2->fetchall_arrayref();
#########################################
my @unique;
my @overlap;

my %hash;
foreach my $result_gal (@$tbl_ary_ref_g1) {
 my $key = join '*|*', @{$result_gal};
 $hash{ $key }++;
}

undef  (@$tbl_ary_ref_g1);

foreach my $result_lab (@$tbl_ary_ref_l1) {
 my $key = join "*|*", @{$result_lab};
 $hash{ $key }++;
}

undef (@$tbl_ary_ref_l1);

foreach my $result_gal2 (@$tbl_ary_ref_g2) {
 my $key = join "*|*", @{$result_gal2};
 $hash{ $key }++;
}

undef  (@$tbl_ary_ref_g2);

foreach my $key ( keys %hash ) {
 if ( $hash{ $key } == 1 ) {
  my @array = split ( /\*\|\*/, $key );
  push @unique, [@array];
 } else {
  my @array = split /\*\|\*/, $key;
  push @overlap, [@array];
 }
}

#########################

use Data::Dumper;
print "Overlap:\n";
print Dumper @overlap;
print "Unique:\n";
print Dumper @unique;

The results of this scripts are:

Overlap:
$VAR1 = [
          'alfa',
          '10'
        ];
Unique:
$VAR1 = [
          'gamma'
        ];
$VAR2 = [
          'gamma',
          '12'
        ];
$VAR3 = [
          'beta',
          '11'
        ];


Ok this is quite good but still is not what I was looking for.
The results that I expect against the 3 query is only (beta 11), couse is
the only couple that is really unique...
Any clues?

Vito Pascali

Reply via email to