in reply to best way to convert to UTF8 from UTF16
#!/usr/bin/perl # Usage: # utf16to8.pl infile > outfile use strict; use warnings; binmode(STDOUT, ':raw:encoding(UTF-8)'); for my $qfn (@ARGV) { # Assumes the presence of a BOM. open(my $fh, "<:raw:encoding(UTF-16)", $qfn) or die("Can't open \"$qfn\": $!\n"); print while <$fh>; }
:raw is needed to disable the crlf layer if present. It would corrupt the data on the UTF-16 side, and the UTF-8 sides needs it to mirror the UTF-16 side.
|
|---|