use strict;
use warnings;
use IO::File;
my $fh=new IO::File("> conf.txt");
$fh=print("abc\n");
abc在conf.txt文件中要写成unicode字符,一个字符由两个自己构成。即:6100 6200 6300。
请问,我该怎么办?
3 个解决方案
#1
$fh=print("\u0061\u0062\u0063\u000d\u000a");
不知道这样行不行,试试看吧。
#2
use strict;
use Encode;
open( FILE, ">:utf8", "conf.txt" ) || die "Failed to open conf.txt : $!\n";
print FILE "abc\n";
close( FILE );
use Encode;
open( FILE, ">:utf8", "conf.txt" ) || die "Failed to open conf.txt : $!\n";
print FILE "abc\n";
close( FILE );
#3
use strict;
use warnings;
use IO::File;
use Encode;
my $f=new IO::File("> abc.txt");
if(!$f)
{
print("$!");
exit(1);
}
$f->binmode(":raw");
$f->print(chr(0xFE),chr(0xFF));
$f->print(encode("UCS-2LE","abc"));
$f->close();
#1
$fh=print("\u0061\u0062\u0063\u000d\u000a");
不知道这样行不行,试试看吧。
#2
use strict;
use Encode;
open( FILE, ">:utf8", "conf.txt" ) || die "Failed to open conf.txt : $!\n";
print FILE "abc\n";
close( FILE );
use Encode;
open( FILE, ">:utf8", "conf.txt" ) || die "Failed to open conf.txt : $!\n";
print FILE "abc\n";
close( FILE );
#3
use strict;
use warnings;
use IO::File;
use Encode;
my $f=new IO::File("> abc.txt");
if(!$f)
{
print("$!");
exit(1);
}
$f->binmode(":raw");
$f->print(chr(0xFE),chr(0xFF));
$f->print(encode("UCS-2LE","abc"));
$f->close();