APM: chokes on dos formatted csv file
Wayne Walker
wwalker at bybent.com
Wed Sep 24 10:15:44 PDT 2008
I don't do much perl anymore, but in the CSV_XS man page there is a
flag where you specify the line delimiter. You just have to change that
before you read the file in.
On Wed, Sep 24, 2008 at 11:39:46AM -0500, Keith Howanitz wrote:
> 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;
> _______________________________________________
> Austin mailing list
> Austin at pm.org
> http://mail.pm.org/mailman/listinfo/austin
--
Wayne Walker
wwalker at bybent.com Do you use Linux?!
http://www.bybent.com Get Counted! http://counter.li.org/
Perl - http://www.perl.org/ Perl User Groups - http://www.pm.org/
Jabber: wwalker at jabber.bybent.com AIM: lwwalkerbybent
IRC: wwalker on freenode.net
More information about the Austin
mailing list