homeveg has asked for the wisdom of the Perl Monks concerning the following question:
Dear PerlMonks,
I am currently trying to use a perl DBI module to store my data in dbi:DBM:mldbm=Storable database.
Original data is loaded from a text file using RegExps. The resulting table contains about 5k rows and several columns and does not have any missing values.
My problem is that while I am parsing the data to a database, only some rows from my original table are converted to a DB entree and, unfortunately, I don't see the reason for that.
I will be very grateful for any help or ideas how to overcome this obstacle.
Here is simplified code I am having problems with:
#/local/bin/perl -w use DBI; use strict "vars"; #initialize database my $dbh = DBI->connect('dbi:DBM:mldbm=Storable'); $dbh->{RaiseError} = 1; #create table to store data my $sth = $dbh-> prepare("CREATE TABLE hist_mod_score (Index INTEGER, Col1 char(30) +, Col2 char(7),Col3 char(4) )"); $sth->execute; my $sql = 'INSERT INTO hist_mod_score (Index, Col1, Col2,Col3) VAL +UES (?,?,?,?)'; $sth = $dbh->prepare($sql) or die $dbh->errstr; # open input file containing raw data open(INPUT, "Input.txt") || die "Can't open input file for reading!:$! +\n"; my $index=0; while (<INPUT>) { for my $chank (split/\n/) { $chank =~/RegExp to extract data from string/; my $Col1 = $1; my $Col2 = $2; my $Col3 = $3; my @arguments = ($index, $Col1,$Col2,$Col3); # check if regexp works fine print STDERR join("\t",@arguments),"\n"; #parse arguments to a DB $sth->execute(@arguments) or die $sth->errstr; $index++; } } $sth->finish; close (INPUT); # check if all data is parsed correctly $sth = $dbh->prepare(" select * from hist_mod_score "); $sth->execute(); $sth->dump_results if $sth->{NUM_OF_FIELDS};
In the result, I've got only 107 from 4800 rows parsed and I did not get any warning or error message.
Thanks in advance for your help!
UPDATE
I have found a problem - in my case it was the Storable driver. I created new SQLite DB and my code works now.Thanks to everybody for your help!
|
|---|