Well, for starters, I'd suggest you take a look at open, split, strict and DBI.

You may also want to read perlre, in case you need regular expressions for matching your data.

The following is similiar to what you may be trying to achieve:
# enable strict syntax use strict; # load the DBI module (for database connectivity) use DBI; # open connection to database. when you use strict, you # need to declare your variables with 'my'. this a good # thing. trust me. my $dbh = DBI->connect("DBI:mysql:databasename", "user", "password", { +RaiseError => 1}); # create a statement handle. the question marks a # placeholders, which simply denote the place you'll # put your data my $sth = $dbh->prepare("INSERT INTO table (column1, column2) VALUES ( +?, ?)"); open FH, "myfile.txt" or die "Can't open myfile.txt: $!\n"; until ( eof FH ) { my @data; for (1..7) { my $line = <FH>; # slurp in new line chomp; # remove trailing newline character push @data, $line; # add current line to data array } # # do stuff with @data # # actually the data insert into the database $sth->execute( $var1, $var2 ); } close FH; $dbh->disconnect();
It's a sketch. It won't work, but it'll get you started. And buy a book! Programming Perl's pretty good :)

ar0n ]


update: you're right; i forgot to add $dbh->disconnect(). too used to apache::dbi, i guess ;)

In reply to (ar0n) Re: reading from txt file and inserting into database tables by ar0n
in thread reading from txt file and inserting into database tables by shaileshsp

Title:
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, details, 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, summary, 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.