APM: chokes on dos formatted csv file
Keith Howanitz
howanitz at gmail.com
Wed Sep 24 09:39:46 PDT 2008
This sample runs great if the file is Unix formatted, but if I upload
a file from a windows system it dies with error:
Error getting csv data. (Bad file descriptor) at ./test-csv2 line 13,
<MYCSV> line 1.
Any suggestions?
#!/usr/bin/perl -w
use strict;
use Text::CSV_XS;
my $csv = Text::CSV_XS->new ();
chomp (my $FN = $ARGV[0]);
open MYCSV, $FN
or die "Error opening csv file. ($!)";
while (<MYCSV>) {
chomp;
$csv->parse($_)
or die "Error getting csv data. ($!)"; #this is where it dies on
a dos formatted file
my @list = $csv->fields; #split fields into @list
print $list[1] . "\n";
}
close MYCSV;
More information about the Austin
mailing list