Text::CSV or Text::CSV_XS is the way to go, but it can be done more conventionally, just in case the module is not available or you want to roll your own.
.......connect to database....... .........upload CSV file .......... my $stmt ="DELETE FROM list" ; my $sth = $dbh->prepare($stmt); $sth->execute(); $stmt =qq/LOAD DATA LOCAL INFILE "..\/$csvtoupload" INTO TABLE list FI +ELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" LINES TERMINATED B +Y "\r" IGNORE 1 LINES/; $sth = $dbh->prepare($stmt); $sth->execute(); unlink "../$csvtoupload" or die "Error deleting uploaded file: $!\n"; ...close db.....
Of course, a bit more needs to be known about the original CSV, like does the first row need to be ignored.
In reply to Re: Load CSV file into Database
by bradcathey
in thread Load CSV file into Database
by fauria
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |