use Text::CSV::Simple; my $parser = Text::CSV::Simple->new; $parser->want_fields(0, 1, 2, 4); my @CSV_File = $parser->read_file($_[0]); &SQL('connect'); for my $row(@CSV_File) { my @CSV_Row = @$row; my ($FN, $LN, $SSN, $Title) = @CSV_Row; my ($do1, $do2); $Check="SELECT id, lastname, firstname, ssn FROM member WHERE UPPER(lastname) = '$LN' AND UPPER(firstname) = '$FN')"; # Find matching member &Execute($Check, 1); while (my ($id, $ln, $fn, $sn)=$sth->fetchrow_array()) { $do1="INSERT DELAYED INTO reports (lastname, firstname, title, ID) VALUES ('$ln', '$fn', '$Title', '$id')"; $do2="UPDATE LOW_PRIORITY member SET working = 'Y' WHERE (ID = '$id') LIMIT 1"; if ($SSN ne $sn) { &LogEvent("Fail SSN: $SSN for $id"); # Compare SSN for exact match } else { &Execute($do1); &Execute($do2); } &LogEvent("Success"); } # END WHILE sub SQL { $dbh = DBI->connect("DBI:mysql:DBname","$un","$pw") || Terminate('Sorry, Disconnecting'); # Prints error . $_[0] } # END SQL sub Execute { if ($_[1] == 1) { $sth = $dbh->prepare( $_[0] ) || &Terminate('Sorry, not Preparing'); $sth->execute || &Terminate('Not Executing'); } else { $dbh->do( $_[0] ) || &Terminate('No Do'); warn( $DBI::errstr ) if ( $DBI::err ); $rc=$dbh->disconnect(); } # END Execute