I would love to help with expressing that I've been here for a few weeks.
I'm trying to open an XML file in Perl in encoding utf-16.
I am able to create the file in utf-8 but it does not suit me and more than that it causes me problems.
Please see if the following sample code complies with your requirements
use strict;
use warnings;
use Encode qw/encode decode/;
my $filename = 'utf16_1.txt';
open my($out), '>:encoding(UTF-16LE)', $filename
or die "Couldn't open $filename";
my $string = 'Sample data';
print $out $string;
close($out);
other variation
use strict;
use warnings;
use Encode qw/encode decode/;
my $filename = 'utf16_2.txt';
open my($out), '>:raw', $filename
or die "Couldn't open $filename";
my $string = 'Sample data';
print $out encode("UTF-16LE", $string);
close($out);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With