Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"utf8 "\x96" does not map to Unicode at <somefile.pl> at line no - 321" Error in Perl

I am setting up Perl application . I am getting this error. "utf8 "\x96" does not map to Unicode at" Can anybody let me know the cause and solution. Am i missing any configuration or it is my installation problem ?

Following is the code :

open(FILE,"<:encoding(UTF-8)",$self->{BASEDIR}.$self->{FILENAME}) || die "could not open file $basedir$filename - $!";
like image 915
Bhushan Avatar asked Aug 05 '11 04:08

Bhushan


3 Answers

The character 0x96 is not a valid UTF-8 encoding. There is a block of code points just above 0x80 that, in UTF-8, encodes the start of a 2- or 3-byte character.

The input you are reading must not be UTF-8, and is most likely Latin1 or CP1252.

You will need to convert the input data to UTF-8, however one does that in Perl (it's been a long time since I did any Perl and it didn't use UTF-8 by default when I was writing Perl :-)

like image 103
Jim Garrison Avatar answered Nov 09 '22 13:11

Jim Garrison


I suspect that something you believe to be encoded in UTF-8 is not, in fact, encoded with UTF-8.

like image 38
Hugh Avatar answered Nov 09 '22 14:11

Hugh


Just putting this info out there in case it helps someone in the future.

If you're working with a Microsoft product, this can be caused by non-US characters (European, Chinese, etc). For instance, if someone sends you an excel spreadsheet of data that you need to process and it's saved in .csv format, those characters can be outside of the utf-8 range if it wasn't saved properly.

Fortunately, at least in Excel for Mac v. 15, it is possible to take that data and "save as" specifically a CSV UTF-8 file - it's in the list of options. This is a separate option from the other CSV file option. This will convert non-US characters into the UTF-8 charset and solve this issue.

like image 40
Mik Avatar answered Nov 09 '22 13:11

Mik