with.a.twist has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI - need for speed
by VSarkiss (Monsignor) on May 13, 2002 at 21:15 UTC | |
|
Re: DBI - need for speed
by Elian (Parson) on May 13, 2002 at 21:21 UTC | |
|
Re: DBI - need for speed
by techwolf (Novice) on May 13, 2002 at 20:34 UTC | |
by with.a.twist (Novice) on May 14, 2002 at 14:30 UTC | |
|
Re: DBI - need for speed
by graff (Chancellor) on May 13, 2002 at 21:31 UTC | |
|
Re: DBI - need for speed
by with.a.twist (Novice) on May 14, 2002 at 00:41 UTC | |
|
Re: DBI - need for speed
by thor (Priest) on May 14, 2002 at 01:25 UTC |