Marklitz has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I want to compare the contents of 2 tables. my 2 tables are as:
Table1 ----------- C1 ---------- dos mou com dis cus ion
Table2 ------------ C1 ----------- mouse discussion computer
I want to compare the data and find out whether table1 contents are contained in table 2 or not. i.e. i want my output as...
mou is present in mouse com is present in computer dis is present in discussion cus is present in discussion ion is present in discussion
I tried by:
my $check =dbh->prepare("SELECT Table.C1, Table.C2 FROM Table1, Table2 + WHERE Table.C1 LIKE Table.C2"); $check->execute(); print "rows present:" + $check->rows; while(@rows = $query->fetchrow_array()) { echo $row['Table1.C1'].is.present.in.$row['Table2.C2']; }
But while executing this, am getting an error
Cant't call method "execute" on an undefined value at ./filename line +123
Please help.. Thanks in advance

Replies are listed 'Best First'.
Re: compare 2 tables of mysql in perl
by moritz (Cardinal) on Jun 22, 2009 at 13:57 UTC
    The error message means that $check is undef, ie probably $dbh->prepare(...) (I hope there's a $ in front) went wrong. Try setting the RaiseError option during DBI->connect to see what went wrong.

    See DBI for more information on error handling.

Re: compare 2 tables of mysql in perl
by Anonymous Monk on Jun 22, 2009 at 13:56 UTC
    | V my $check =dbh->prepare ^ |
    $check is undef, if you use DBI RaiseError => 1 option you can get automatic error messages , telling you why prepare failed
Re: compare 2 tables of mysql in perl
by CountZero (Bishop) on Jun 22, 2009 at 14:56 UTC
    Your SQL should read
    SELECT Table1.C1, Table2.C1 FROM Table1, Table2 WHERE Table1.C1 LIKE ' +%Table2.C1%'

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: compare 2 tables of mysql in perl
by Anonymous Monk on Jun 22, 2009 at 13:58 UTC
    echo $row['Table1.C1'].is.present.in.$row['Table2.C2']; Echo? ENOPERL :)