Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Joining two files on common field

by jZed (Prior)
on Sep 22, 2005 at 20:38 UTC ( [id://494293]=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://494293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 21:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found