
Kanji
User
/ Moderator
Jun 15, 2000, 10:25 PM
Post #2 of 2
(2099 views)
|
Re: Survey script to Access Database
[In reply to]
|
Can't Post
|
|
Use the DBI suite of modules. DBD::ODBC can handle the Access portion, and you can use DBD::CSV or DBD::RAM for the text file. Depending on your text, the latter's probably overkill as you could get away with something like ... <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!perl use DBI; my $dbh = DBI->connect("dbi:ODBC:MyAccessDB") | | die $DBI::errstr; my $sth = $dbh->prepare("INSERT INTO tables VALUES (?,?,?,?)") | | die $dbh->errstr; open TEXT, "MyTextDB.txt" | | die "Can't open MyTextDB.txt: $!"; while(<TEXT> ) { chomp; my(@values) = split /,/, 4; $sth->execute(@values) | | die $sth->errstr; } $sth->finnish; $dbh->disconnect;</pre><HR></BLOCKQUOTE> ... which would populate your Access db assuming it's four fields corresponded to four comma seperated fields in your text file. You can download DBI, DBD::ODBC, and DBD::CSV via ppm (if you use ActiveState's perl) or CPAN (if you use one of the other varieties).
|