It's a sketch. It won't work, but it'll get you started. And buy a book! Programming Perl's pretty good :)# 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();
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |