Skip to content

Instantly share code, notes, and snippets.

@emjayess
Created March 4, 2011 22:58
Show Gist options
  • Save emjayess/855867 to your computer and use it in GitHub Desktop.
Save emjayess/855867 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment