in reply to Reading from a file and writing the content into a database
When I've done similar things in the past (though not using an Access database), I've used DBI to write to the database. I've just looked at CPAN, and there seems to be an ODBC plugin for DBI (DBD::ODBC).
I don't know what kind of information you have in the file, but in general, I'd do something like this:
use DBI; # connect to the database my $dbh = DBI->connect('dbi:ODBC:foo', 'username', 'password') or die "Can't connect: ", $DBI::errstr; # prepare a SQL statement to insert your data # (using placeholders ("?") so you only have to # compile the statement once) my $sth = $dbh->prepare(<<SQL) or die "Can't prepare: ", $dbh->errstr; insert into data (data_1, data_2) values (?, ?) SQL # open up your data file open FH, "data_file" or die "Can't open: $!"; while (<FH>) { chomp; # parse your data out of the file my($d1, $d2) = split /\t/; # assuming tab-separated data # mess around with your data here # .... # insert your data into the database $sth->execute($d1, $d2); } close FH; $sth->finish; $dbh->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Reading from a file and writing the content into a database
by chromatic (Archbishop) on Mar 31, 2000 at 22:32 UTC | |
by btrott (Parson) on Mar 31, 2000 at 23:03 UTC | |
|
RE: Re: Reading from a file and writing the content into a database
by Anonymous Monk on Apr 01, 2000 at 01:44 UTC | |
by btrott (Parson) on Apr 01, 2000 at 02:19 UTC |