#!/usr/bin/perl
#
use strict;
use warnings;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new();
#open (CSV, "<", $file_to_parse) or die "Could not open '$file' $!
";
while (my $line = ) {
chomp $line;
if ($csv->parse($line)) {
my @columns = $csv->fields();
$columns[0] =~ s/ //g;
$columns[2] =~ s/ //g;
if( ($columns[0]=~/^[0-9]+$/) && ($columns[2]=~/^[0-9]+$/) ) {
print "Format ok\n"; foreach (@columns){print $_,"\t";};
print "\n";
}else{
print "Wrong Format\n";
print "First $columns[0] and tird $columns[2] have to be numeric\n";
}
}else{
my $err = $csv->error_input;
print "
$err Failed to parse line, please call for help!
" if $err;
}
}
__DATA__
12345,John Dow, 123456
54321,ANDREW MALL, 8888882
987865,BOGGS BUNNY, 2234566
88777,CLARK KENT R, 888666
126677,CLARK KENT R, xx345778
112222,DAVOLIO DARK F, 3321777