Code first (code works great, but...):
I'm checking to see if data exists in a table. If it doesn't, I'm adding it. My SRCFILE has at least 8000 records in it. Is there a faster/better way to do this? Thanks so much.open(SRCFILE, $infile) or die print "Could not open $infile\n"; while($line=<SRCFILE>) { ##### prepare line data $groupnumber=substr($line,863,9); # extract group number $groupnumber =~ s/^\s+//; # Trim leading spaces $groupnumber =~ s/\s+$//; # Trim trailing spaces ##### execute prepared sql statment with linedata parameter $sth->execute($groupnumber) or die print "Unable to execute: $DBI::err +str\n"; ##### fetch recordset if ( $resultset = $sth->fetchrow_array()) { # # groupnumber is in the database (move to the next line) # } else { # else there was no record in the database matching this query. # we'll place this record into the database now. print localtime() . " $groupnumber being inserted into database\n"; $dbh->do("insert into part_group(part_group) Values ($groupnumber)") or die print "Could not insert $groupnumber into part)group: $DBI::er +rstr\n"; } } close(SRCFILE);
In reply to DBI - need for speed by with.a.twist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |