use Text::CSV_XS; use IO::Handle; use Carp qw(croak); my $file = $ARGV[0]; my $parser = Text::CSV_XS->new({ binary => 1, always_quote => 1, escape_char => '\\', #' help emacs }); # open input and output temp files open(my $in_fh, '<', $file) or croak("Unable to open input file $!"); my $line_num = 0; # Using while(1) here and exiting via last() so we can avoid testing to see # if it's the last line (with eof) more than once per line. while (not eof($in_fh)) { $line_num++; # parse the row and handle any errors my $in_values = $parser->getline($in_fh); croak("Unable to parse line $line_num of file $file: " . $parser->error_input()) if !$in_values; } close $in_fh or croak("Error closing file $file: $!"); #### SELECT blah blah blah INTO OUTFILE ? FIELDS TERMINATED BY ',' ESCAPED BY '\\' ENCLOSED BY '"' LINES TERMINATED BY '\n'