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;
In reply to Re: Reading from a file and writing the content into a database
by btrott
in thread Reading from a file and writing the content into a database
by Kiko
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |