in reply to Joining two files on common field

Well you didn't say what you want to do with the results, but assuming you want them in an Array of Arrays:
use DBI; my $dbh=DBI->connect('dbi:CSV(RaiseError=1):'); my $results = $dbh->selectall_arrayref(" SELECT * FROM file1 NATURAL JOIN file2 ");

Replies are listed 'Best First'.
Re^2: Joining two files on common field
by ch1 (Novice) on Sep 22, 2005 at 22:54 UTC
    Here is code but I'm getting an error.
    #!/usr/bin/perl -w use DBI; $dbh = DBI->connect("DBI:CSV:f_dir=/home/turn2sp/tmp") or die "Cannot connect: " . $DBI::errstr; $dbh->{'csv_tables'}->{'Matrix'} = { 'file' => 'Matrix.csv'}; $dbh->{'csv_tables'}->{'Inventory'} = { 'file' => 'Inventory.csv'}; $sth = $dbh->prepare("SELECT * from Matrix NATURAL JOIN Inventory"); #$sth = $dbh->prepare("SELECT * FROM Inventory"); $sth->execute(); while ( @row = $sth->fetchrow_array ) { print "@row\n"; }
    DBD::CSV::db prepare failed: Parse error near NATURAL JOIN Inventory at /usr/lib/perl5/site_perl/5.8.4/i686-linux/DBD/File.pm line 195. for Statement "SELECT * from Matrix NATURAL JOIN Inventory" at ./j line 7. Can't call method "execute" on an undefined value at ./j line 10.
        I don't know how to check which version of SQL::Statement I'm using?
      To get a better error message, change
      $sth = $dbh->prepare("SELECT * from Matrix NATURAL JOIN Inventory");
      to
      $sth = $dbh->prepare("SELECT * from Matrix NATURAL JOIN Inventory") or die "Cannot prepare: " . $DBI::errstr;