title: CSV import to MySQL
body: <p>Hi I keep getting an error when trying to run the following perl script to import a csv file into an existing mysql database table. Every time I run it I get the message "Died at /home/perl/dep_import_2.pl line 10.</p>
  
  <p>Any help would be appreciated </p>
  
  <p>Thanks</p>
  
  <pre><code>#!/usr/bin/perl
  
  use DBI;
  use DBD::mysql;
  use warnings "all";
  
  
  if ($#ARGV != 0) {
     print "Usage: dep_import_2.pl filename\n";
       die;
  }
  $filename = $ARGV[0];
  
  
  # MySQL CONFIG VARIABLES
  $host = "localhost";
  $user = "standard";
  $pw = "standard";
  
  $database = "data_track";
  $dsn = "DBI:mysql:database=" . $database . ";host=" . $host;
  
  $dbh = DBI-&gt;connect($dsn, $user, $pw)
     or die "Can't connect to the DB: $DBI::errstr\n";
  
  print "Connected to DB!\n";
  
  open FILE, "/home/dep/new_study_forms_2.csv", $filename or die $!;
  
  $_ = &lt;FILE&gt;;
  $_ = &lt;FILE&gt;;
  
  while (&lt;FILE&gt;) {
      @f = split(/,/, $_);
  
      $sql = "INSERT INTO dep (date, subject, weight, size, time, hi_pre, hi_post, hi_afternoon, hi_test, actical_on, actical_off, saggital_1, saggital_2, crown_heel1, crown_heel2, crown_rump1, crown_rump2, scan, record_number, tap, sample, dye, left_chip, right_chip) VALUES('$f[0]', '$f[1]', '$f[2]', '$f[3]' '$f[4]', '$f[5]', '$f[6]', '$f[7]', '$f[8]', '$f[9]', '$f[10]', '$f[11]', '$f[12]', '$f[13]', '$f[14]', '$f[15]', '$f[16]', '$f[17]', '$f[18]', '$f[19]', '$f[20]', '$f[21]', '$f[22]', '$f[23]')";
      print "$sql\n";
      my $query = $dbh-&gt;do($sql);
  }
  </code></pre>