emjayess
3/4/2011 - 10:58 PM

one basic approach to chunking/parsing a csv using Text::CSV

one basic approach to chunking/parsing a csv using Text::CSV

#!/usr/bin/perl 

# modes
use strict;
use warnings;

# modules
use Text::CSV;

my $csv = 'DATA.TXT';
my $engine = Text::CSV->new();

open (CSV, "<", $csv) or die $!;

while (<CSV>) {
	next if ($. == 1); #short-circuit on the header row
	if ($engine->parse($_)) {
		my @columns = $engine->fields();
		print "@columns[0] : @columns[2] ( @columns[13] )\n";
	}
	else {
		my $err = $engine->error_input;
		print "Failed to parse line: $err";
	}
}

close CSV;