0

This question is similar to others that have been posted before. however trying all combinations nothing is working.

I need to have my excel file read in Unicode Utf8, I am attempting to set my bom:

my $csv = Text::CSV->new ({binary=>1, eol =>$/}) or die "cannot use CSV: ".Text::CSV->error_diag (); open my $csvFile, ">:encoding(UTF-8)", "teht.csv" or die "teht.csv: $!"; print($csvFile "\x{FEBBBF}");

however this gets an errror and says that "0xFEBBBF is not Unicode..."

all information that I have found indicates that the code for utf8 should read print($csvFile "\N{U+FEBBBF}") or ... "\xFE\xBB\xBF" or similar.

Is it possible to force Excel recognize UTF-8 CSV files automatically? is one source which says this many times.

https://stackoverflow.com/a/22711105/6557829 is another source.

So far I have actually been able to get UTF-16 to work with the same print statement: print($csvFile "\N{U+FEFF}"); however that is more space than I mean to use. Thanks in advance for any help you can give me.

Community
  • 1
  • 1

1 Answers1

2

The BOM is U+FEFF, not U+FEBBBF. Replace

"\x{FEBBBF}"

with any one of following:

chr(0xFEFF)
"\x{FEFF}"
"\N{U+FEFF}"
"\N{BOM}"

This will create a string with a single character (FEFF), which print will encode using UTF-8 as requested (EF BB BF).

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • that should be for utf-16 coding, but I am looking for utf8 I was saying how that works when I do either of the first two options that you reccomended, however I mean to use 8 bits not 16 – WorkingOnBeingBetter Aug 22 '16 at 19:22
  • Did you try it? You would have seen that you are mistaken. See the added paragraph. – ikegami Aug 22 '16 at 19:23