Brendan L. Brendan L. - 1 year ago 45
Perl Question

setting BOM to Unicode U code UTF8 perl

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}")
... "\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. 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.

Answer Source

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


with any one of following:


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