#!/usr/bin/perl use strict; use warnings; use Text::CSV_XS; my $file = $ARGV[0]; my $xs = Text::CSV_XS->new({'strict' => 1,'auto_diag' => 2}); open(my $handle,$file); $xs->column_names(['one','two','three']); while(my $line = $xs->getline($handle)) { print Dumper($line)."\r\n"; } close($handle); #### $ cat test.csv this,is,a test,of,the csv,parser,logic #### $ ./csv_test.pl test.csv $VAR1 = [ 'this', 'is', 'a' ]; $VAR1 = [ 'test', 'of', 'the' ]; $VAR1 = [ 'csv', 'parser', 'logic' ]; # CSV_XS ERROR: 2014 - ENF - Inconsistent number of fields @ rec 4 pos 1