Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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!


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!

In reply to Perl DBI: problems inserting data to a table by homeveg

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (14)
    As of 2018-11-20 13:32 GMT
    Find Nodes?
      Voting Booth?
      My code is most likely broken because:

      Results (224 votes). Check out past polls.