1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/perl
use strict;
use Text::CSV;
my $file = 'Contacts.csv';
my $csv = Text::CSV->new({sep_char => ';', binary => 1});
my @titreCols = ( "contact_id",
"company_id",
"last_name",
"title",
"email1",
"work_phone",
"work_phone_ext",
"cell_phone",
"home_phone",
"fax",
"user_id",
"entered_id",
"entered_by",
"last_modified_at",
"last_modified_by",
"contact_record_status");
open (CSV, "<", $file) or die $!;
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
my $nbcols = scalar @columns;
print "\n\n";
for my $i (0 .. $nbcols) {
print "\n",$titreCols[$i],"->",$columns[$i];
}
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV; |
Partager