Link to home
Start Free TrialLog in
Avatar of kyle972
kyle972

asked on

Perl CSV Ignore First Line and Export to Access

I am trying to insert the values from a CVS file (with the first row being headers) into an Access Database using a Perl script. The script works, but i need to exclude the first line of the csv file which contains the headers.

Any ideas?
use DBI;

$csvfile="C:/WeatherModel/degrib/bin/Model/Output/gfs_2010111900_72.csv";

$dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=c:/weathermodel/weathermodel.mdb', '', '');
$sth = $dbh->prepare( "INSERT INTO GFS_Forecasts VALUES (?,?,?,?,?,?)" );

open CSV, $csvfile;

while(<CSV>) {
  chomp;
  my @fields = split /,/;
  $sth->execute(@fields);
}

close CVS;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tel2
tel2
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial