Вопрос

- это CWD модуль, касающийся Unicode, не в курсе или должен быть использован только для использования толькоПри записи в ОС?

#!/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 ☺
.

Это было полезно?

Решение

The Cwd module uses char * types internally and so does not handle encoding at all. Generally, filesystems do not care what characters or encoding you use for your filenames, as long as you escape any special characters (e.g. '/')

If you want to tell Perl the file path is in UTF-8, you can encode it:

use Encode qw(decode_utf8);

...
say decode_utf8(abs_path $file);

Другие советы

Perl leaves it to you to decode paths it returns and encode paths you provide. (YUCK!)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top