Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

prepare insert statement outside while loop for speed

by Anonymous Monk
on Dec 01, 2010 at 19:28 UTC ( #874720=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks

I am new to perl and trying to get to grips with the dbi. Is this the correct way to prepare an insert statement outside a while loop for speed?

my $insert_snp_sql = "insert into $tableName (Chr, Pos_start, Pos_end, + id, reference, genotype) values (?,?,?,?,?,?)"; my $sth = $db->prepare ($insert_snp_sql); while(<INFH>){ #process input line and then insert to database if ($sth->execute($data[0],$data[1],$data[2], $data[3], $data[ +4],$data[5])) { #insert ok } }
thanks a lot

Comment on prepare insert statement outside while loop for speed
Download Code
Re: prepare insert statement outside while loop for speed
by JavaFan (Canon) on Dec 01, 2010 at 20:34 UTC
    Yes.
      thanks!
Re: prepare insert statement outside while loop for speed
by McDarren (Abbot) on Dec 02, 2010 at 05:19 UTC
    $sth->execute($data[0],$data[1],$data[2], $data[3], $data[4],$data[5])
    The above could be written a bit more succinctly as:
    $sth->execute(@data[0 .. 5])
    See Slices

    Or, if you know that @data will always contain just six elements, then just simply:

    $sth->execute(@data)
    Hope this helps,
    Darren

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://874720]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-29 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls