in reply to Re: Is there a more efficient way?
in thread Is there a more efficient way?
<readmore><c> #!/usr/bin/perl -w use strict; use warnings; use DBI; ################################################ # Load the files into the MySQL database # ################################################ my $dbh = DBI->connect("DBI:mysql:dev:informatics", "mystuff", "gene77 +7" ) || die "Could not connect to database:\$DBI::errstr"; my $sth1 = $dbh->prepare("INSERT INTO dev.blocks (names)VALUES(?)"); + my $sth2 = $dbh->prepare("SELECT id from dev.blocks where name = ?"); my $sth3 = $dbh->prepare("INSERT INTO dev.vials (block_id, lt, well_po +sition, gene, barcode)VALUES(?,?,?,?,?)"); # Put all of the files into an array for loading my $count = 0; # loop through the filehandles.treat $file as a normal # file handle my @files my @files; foreach my $file(@files) { open(my $file, "/home/mydir/data/test_files/$file"); while(<$file>) { chomp; my @fields = split /\t/; my $well = $fields[0]; my $gene = $fields[1]; my $lt = $fields[2]; my $barcode = $fields[3]; my $name = $fields[4]; # Insert data into tables # $name indices file are to be loaded into the 'blocks' table +'name' field $sth1->execute($name); # query dev.blocks for id by passing in the $name $sth2->execute($name); # get the result from the blocks table and assign it to a vari +able. my @result = $sth2->fetchrow(); my $id = $result[0]; # Insert the variable into the foreign key block_id in the via +ls table along # with the other variables to be loaded into the vials table. $sth3->execute($id,$lt, $well, $gene, $barcode); } close($ltvec_file); $count++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Is there a more efficient way?
by moritz (Cardinal) on Jul 29, 2009 at 21:30 UTC | |
|
Re^3: Is there a more efficient way?
by mzedeler (Pilgrim) on Jul 29, 2009 at 21:25 UTC |