title: Perl Import large .csv to MySQL, don't repeat data
body: <p>I am trying to import several .csv files into a mysql database, the script below works except that it only imports the first row of my csv data into the database. Both my tables are populated with exactly one data entry.</p>
  
  <p>Any help would be appreciated. </p>
  
  <p>Thank you</p>
  
  <pre><code>#!/usr/bin/perl
  
  use DBI;
  use DBD::mysql;
  use strict;
  use warnings;
  
  # MySQL CONFIG VARIABLES
  my $host = "localhost";
  my $user = "someuser";
  my $pw = "somepassword";
  
  my $database = "test";
  my $dsn = "DBI:mysql:database=" . $database . ";host=" . $host;
  
   my $dbh = DBI-&gt;connect($dsn, $user, $pw)
     or die "Can't connect to the DB: $DBI::errstr\n";
  
   print "Connected to DB!\n";
  
  
  # enter the file name that you want import
  
  my $filename = "/home/jonathan/dep/csv/linux_datetime_test_4.26.13_.csv";
  
  open FILE, "&lt;", $filename or die $!;
  
  $_ = &lt;FILE&gt;;
  $_ = &lt;FILE&gt;;
  
  while (&lt;FILE&gt;) {
     my @f = split(/,/,$_);
  
  if (length($f[4]) &lt; 10) {
              print "No Weight\n"; 
      }
      else {
             #insert the data into the db
             print "insert into datetime_stamp\n"; 
  }
          my $sql = "INSERT INTO datetime_stamp (subject, date, time, weight)                       
  VALUES('$f[1]', '$f[2]', '$f[3]', '$f[4]')";
      print "$sql\n";
          my $query = $dbh-&gt;do($sql);
  
          my $sql = "INSERT INTO subj_weight (subject, weight) VALUES('$f[1]', '$f[2]')";
          my $query = $dbh-&gt;do($sql);
  
  close(FILE);
  }
  </code></pre>