Solved

Perl CSV Ignore First Line and Export to Access

Posted on 2010-11-19
1
589 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:kyle972
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
tel2 earned 500 total points
ID: 34177555
Hi kyle,

If I understand you correctly, you should be able to just insert "<CSV>;" between the "open..." and the "while...", like this:

    ...
    open CSV, $csvfile;
    <CSV>;
    while(<CSV>) {
    ...

That should read one line, and do nothing with it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question