Perl6:来自 IO::Path 的 `dir` 总是以正确的方式解码文件名吗?

Perl6: does `dir` from IO::Path decode the filenames always the right way?

IO::Path 中的函数 dir 是否以正确的方式自动解码文件名,或者是否可以设置编码?


在 Perl5 中,我主要按照建议对输入进行解码并对输出进行编码。

因此,例如在 Perl5 中,如果 OS 用于写入文件名的编码与控制台输出的编码不同,我会这样写。

use Encode::Locale;
use Encode qw(decode);
binmode STDOUT, ':encoding(console_out)';

my @files;
while ( my $file = readdir $dh ) {
    push @files, decode( 'locale_fs', $file );
}
for my $file ( @files ) {
     print "$file\n";
}

在 Perl6 中我不知道我应该做什么。

Perl 6 在内部使用 Unicode 字符串(在 grapheme-based 表示中),编码发生在 IO 边界。

对于控制台输出,您可以通过$*OUT.encoding("...")手动设置编码。

对于目录列表,它取决于后端:使用 JVM,它应该 做正确的事情(或者像 Java 那样失败)。对于 MoarVM,它将取决于平台:在 Win32 上,使用 Unicode API( 应该 做正确的事情),而在其他平台上,UTF-8 is assumed。从该片段可以看出,原则上使用不同编码的能力存在于最低级别,但它似乎没有以任何方式暴露给用户...