Sanjay Rao
Sanjay Rao

Reputation: 548

Parsing fields with special characters using Perl Text::CSV

I am using the Text::CSV module to parse lines into various fields from a tab-separated value file.

Examples of special characters in strings are

"CEZARY Å?UKASZEWICZ, PAWEÅ? WIETESKA","BÜRO FÜR"

My code goes as below:

my $file = $ARGV[0] or die "Need to get TSV file on the command line\n";

my $csv = Text::CSV->new({sep_char => "\t"});

open(my $data,'<', $file) or die "Could not open '$file' $!\n";


while (my $line= <$data>) {

       if($csv->parse($line)){
            my @curr_arr = $csv->fields();

        }
} # end of while

close $data;

The above is some of the important parts of my code. The error I get is as follows:

cvs_xs error : 2026 - EIQ - Binary Character inside quoted field, binary off @pos 15

Upvotes: 5

Views: 1600

Answers (1)

alex
alex

Reputation: 1304

my $csv = Text::CSV->new({ binary => 1, sep_char => "\t"});

Upvotes: 11

Related Questions