Char like "á" causing the data parse to fail...

P

Prasad Gadgil

Hi,

I am processing some data in csv format, in my script using Text::CSV.
The parsing fails for certain records. On printing these entries, all
of them show a junk characher "á".

This is not visible in the input data but only displayed when error is
printed. How do I handle these records ?

regards,
Prasad
 
S

Sherm Pendley

Prasad Gadgil said:
I am processing some data in csv format, in my script using Text::CSV.
The parsing fails for certain records. On printing these entries, all
of them show a junk characher "á".

Perl itself can handle any number of text encodings. Have a look at perldoc
perluniintro for details, but here's a short example. To open a UTF-8 encoded
text file for input, you'd do this:

open(my $fh, '<:utf8', $filename) or die "Error opening $filename: $!";

If the encoding you've specified for a particular file handle doesn't match
that used by Perl internally, both incoming and outgoing text is automatically
converted. This works for both input and output.

So, what you need to do is figure out what encoding is used in the incoming
CSV file, and what's expected in the output. Then, specify that encoding when
you open() those files.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top