#!/usr/local/bin/perl
use warnings;
use strict;
use utf8;
use Encode qw(encode);
my $dir = '/data/Delibes, Léo';
if ( -d $dir ) {
print "OK\n";
}
if ( -d encode 'utf8', $dir ) {
print "OK\n";
}
这会打印 2 次OK
;我想这是因为 Perl 在$dir
内部存储为 utf8。
我有办法检查PerlIO::fse是否对文件测试运算符有影响,只要 perl 和文件系统存储在utf8
?
编辑:
#!/usr/local/bin/perl
use warnings;
use 5.014;
binmode STDOUT, 'utf8';
use utf8;
my $dir1 = 'é';
my $dir2 = chr(0xE9);
opendir my $dh1, $dir1 or warn '1: ', $!;
say "OK1" if -d $dir1;
opendir my $dh2, $dir2 or warn '2: ', $!;
say "OK2" if -d $dir2;
utf8::upgrade( $dir1 );
utf8::upgrade( $dir2 );
opendir my $dh3, $dir1 or warn '3: ', $!;
say "OK3" if -d $dir1;
opendir my $dh4, $dir2 or warn '4: ', $!;
say "OK4" if -d $dir2;
# OK1
# 2: Datei oder Verzeichnis nicht gefunden at ./temp1.pl line 12.
# OK3
# OK4
也许我还没有完全理解它是如何PerlIO::fse
工作的——在这个例子中我看不到任何效果PerlIO::fse
:
#!/usr/local/bin/perl
use warnings;
use 5.014;
binmode STDOUT, 'utf8';
use utf8;
use PerlIO::fse 'utf-8';
my $dir1 = 'é';
my $dir2 = chr(0xE9);
opendir my $dh1, $dir1 or warn '1: ', $!;
say "OK1" if -d $dir1;
opendir my $dh2, $dir2 or warn '2: ', $!;
say "OK2" if -d $dir2;
# OK1
# 2: Datei oder Verzeichnis nicht gefunden at ./temp1.pl line 13.