>
> That sounds only "slightly" different. Please examine the code that I have
> provided and modify it for your own, specific needs.
>
U are right, I think I'm really close to the solution of my problem..
I tried to put all the lesson togheter and I got this script that do what i
want:
#!/usr/bin/perl
use strict;
use warnings;
my @G1 = (["alfa" , "10"], ["beta" , "11"]);
my @L1 = (["alfa" , "10"], ["gamma" , "12"]);
my @G2 =('gamma','teta');
my %unique;
for my $e1 ( @G1 ) {
$unique{$e1->[0]} = $e1->[1];
}
my %overlap;
for my $e2 ( @L1 ) {
my( $key, $val ) = @$e2;
if( exists $unique{$key} ) {
$overlap{$key} = 1;
delete $unique{$key};
}else{
$unique{$key} = $val;
}
}
for my $e3 ( @G2 ) {
delete $unique{$e3};
}
for my $key ( keys %unique ) {
print "Unique: ", "[ $key, $unique{$key} ]\n";
}
This script do what I need but still miss the dbi part. So i tried to put
the stuff again with this script:
######################################################
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use DBD::mysql;
use warnings;
my $db_gal = DBI->connect(
"dbi:mysql:test_gal:localhost:3306","user","password" )
or die( $DBI::errstr . "\n" );
my $SEL_G1 = "select * from GAL";
my $query_handle_gal = $db_gal->prepare($SEL_G1);
$query_handle_gal->execute();
my $tbl_ary_ref_g1 = $query_handle_gal->fetchall_arrayref();
#########################################
my $db_lab = DBI->connect(
"dbi:mysql:test_lab:localhost:3306","user","password" )
or die( $DBI::errstr . "\n" );
my $SEL_L1 = "select * from LAB";
my $query_handle_lab = $db_lab->prepare($SEL_L1);
$query_handle_lab->execute();
my $tbl_ary_ref_l1 = $query_handle_lab->fetchall_arrayref();
##########################################
my $db_gal2 = DBI->connect(
"dbi:mysql:test_gal:localhost:3306","user","password" )
or die( $DBI::errstr . "\n" );
my $SEL_G2 = "select * from GAL2";
my $query_handle_gal2 = $db_gal2->prepare($SEL_G2);
$query_handle_gal2->execute();
my $tbl_ary_ref_g2 = $query_handle_gal2->fetchall_arrayref();
#########################################
#my @G1 = (["alfa" , "10"], ["beta" , "11"]);
#my @L1 = (["alfa" , "10"], ["gamma" , "12"]);
#my @G2 =('gamma','teta');
# populate a hash with the elements of G1
my %unique;
for my $e1 ( @$tbl_ary_ref_g1 ) {
$unique{$e1->[0]} = $e1->[1];
}
# add elements in L1 not in G1
# delete elements in both
my %overlap;
for my $e2 ( @$tbl_ary_ref_l1 ) {
my( $key, $val ) = @$e2;
if( exists $unique{$key} ) {
$overlap{$key} = 1;
delete $unique{$key};
}else{
$unique{$key} = $val;
}
}
for my $e3 ( @$tbl_ary_ref_g2 ) {
delete $unique{$e3};
}
for my $key ( keys %unique ) {
print "Unique: ", "[ $key, $unique{$key} ]\n";
The 3 queries give these results from the cli:
1)
mysql> select * from GAL;
+------+------+
| col1 | col2 |
+------+------+
| alfa | 10 |
| beta | 11 |
+------+------+
2)
mysql> select * from LAB;
+-------+------+
| col1 | col2 |
+-------+------+
| gamma | 12 |
| alfa | 10 |
+-------+------+
3)
mysql> select * from GALILEO2;
+-------+
| col1 |
+-------+
| gamma |
+-------+
Now the script don't do what i was expecting couse it gives me:
Unique: [ gamma, 12 ]
Unique: [ beta, 11 ]
Where i was looking for:
Unique: [ beta, 11 ]
Sure i'm really bad at programmer, bbut really i think im not so far from
the results needed....
Tnx again everybody for the patient, really!
Vito