是关于Unicode的CWD模块不是最新的,还是应该只在写入操作系统时使用abs_path?
#!/usr/bin/env perl
use warnings;
use 5.012;
use utf8;
binmode STDOUT, ':encoding(utf-8)';
use Cwd qw(abs_path);
use File::Spec::Functions qw(rel2abs);
chdir '/tmp';
my $file = "Hello \x{263a}";
open my $fh, '>', $file or die $!;
say $fh 'test';
close $fh;
say abs_path $file;
say rel2abs $file;输出:
# /tmp/Hello âº
# /tmp/Hello ☺发布于 2012-03-02 18:20:58
Cwd模块在内部使用char *类型,因此根本不处理编码。通常,文件系统不关心您的文件名使用什么字符或编码,只要您转义任何特殊字符(例如'/')即可。
如果您想告诉Perl文件路径是UTF-8格式的,您可以对其进行编码:
use Encode qw(decode_utf8);
...
say decode_utf8(abs_path $file);发布于 2012-03-02 17:21:36
Perl让您对它返回的路径进行解码,并对您提供的路径进行编码。(讨厌!)
https://stackoverflow.com/questions/9530397
复制相似问题