January 21, 2010 · CSV LDAP Perl

Parse a csv file using perl

While parsing and converting some CSV files to ldif’s I needed a perl script, the Test::CSV module is helpful :


use strict;
use warnings;
use Text::CSV;

my $file = ‘prospects.csv’;

my $csv = Text::CSV->new();

open (CSV, “) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
print “@columns\n”;
} else {
my $err = $csv->error_input;
print “Failed to parse line: $err”;
close CSV;