Okay... well, then which part are you having trouble with,
since you know how to read the file, and you know how to
write to the 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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|