Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

prepare insert statement outside while loop for speed

by Anonymous Monk
on Dec 01, 2010 at 19:28 UTC ( [id://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

Replies are listed 'Best First'.
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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-19 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found