Created
March 4, 2011 22:58
-
-
Save emjayess/855867 to your computer and use it in GitHub Desktop.
one basic approach to chunking/parsing a csv using Text::CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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