open(SRCFILE, $infile) or die print "Could not open $infile\n"; while($line=) { ##### 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::errstr\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::errstr\n"; } } close(SRCFILE);