我已经在perl中创建了一个用于在txt文件中编写内容的Pl文件,但是当我们在Ubuntu系统中打开文件时,它以UTF8显示内容,在windows系统中,内容以ANSI格式显示,文本被破坏在txt文件中。
我想在Windows系统中使文件UTF8默认打开,这样就不会破坏字符。
以下是我的代码
my $filename = "123.txt";
my $content = "ब लोगों के लिए एक समा sum";
open FILE, ">", $filename;
print FILE $content;
close FILE;
exit;
答案 0 :(得分:0)
另请参阅Encode all standard output as utf-8和Perl Unicode Cookbook: The Standard Preamble
use utf8;
use strict;
use warnings;
use open ':std', ':encoding(UTF-8)';
my $filename = "123.txt";
my $content = "ब लोगों के लिए एक समा sum";
open(my $FILE, ">", $filename)
or die("can't open \"$filename\": $!\n");
print $FILE $content;