Perl 在 Windows 中使用外来字符

标签 perl file utf-8

我正在尝试使用 perl 在 Windows 中打印土耳其语中的 ş,ı,ö,ç 等字符,但我做不到。我的主要目的是在 Windows 中使用特殊字符创建文件夹。

这是我的代码:

    use Text::Iconv;
    use strict;
   use warnings;
    $conve = Text::Iconv->new("windows-1254","UTF-16");
    $converted = $conve->convert("ş");
    print $converted;
    system("mkdir $converted");

我在第 7 行收到格式错误的 utf-8 字符(字节 0xfe)aa.pl

最佳答案

将以下内容另存为 UTF-8:

use utf8;
use strict;
use warnings;
use open ":std", ":encoding(cp1254)";  # Set encoding for STD*
use Encode qw( encode );

my $file_name = "ş";
print "$file_name\n";
system(encode('cp1254', qq{mkdir "$file_name"}));

use utf8 告诉 Perl 源代码是 UTF-8。

use open ":std", ":encoding(cp1254)"; 导致发送到 STDOUT 和 STDERR 的文本使用 cp1254 进行编码,并导致从 STDIN 读取的文本从 cp1254 解码.

它不会影响发送到系统调用(例如system)的内容,因此您需要对它们进行显式编码。

关于Perl 在 Windows 中使用外来字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9556829/

相关文章:

perl - 如何仅从 Perl 程序的主包获取跟踪输出

perl - 鹦鹉到底是什么?

使用带有线程锁的文件句柄时出现Python错误 "I/O operation on closed file"

Mysql:设置列字符集

java - 字符串编码转换 UTF-8 到 SHIFT-JIS

perl - perl中如何将U+XXXXX序列转换为字符?

perl - 如何在 Perl 中使用散列作为子例程的参数?

c++ - 在 C++ 中读取文件标签/属性

node.js - 当库需要文件路径 Node 时传入缓冲区

php - SVN合并具有不同字符集的分支