Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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;

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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (5)
    As of 2018-03-24 10:31 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (298 votes). Check out past polls.