如何使用Perl在Windows中创建Unicode文件名 [英] How do you create unicode file names in Windows using Perl

查看:66
本文介绍了如何使用Perl在Windows中创建Unicode文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

use utf8;
open($file, '>:encoding(UTF-8)', "さっちゃん.txt") or die $!;
print $file "さっちゃん";

但是我得到的文件名为ã•ã£ã¡ã‚ƒã‚.txt

But I get the file name as ã•ã£ã¡ã‚ƒã‚".txt

我想知道是否有一种方法可以像我期望的那样(意味着我有一个unicode文件名)而不求助于Win32 :: API,Win32API :: *或移动到另一个平台并使用Samba共享以修改文件.

I was wondering if there was a way of making this work as I would expect (meaning I have a unicode file name) this without resorting to Win32::API, Win32API::* or moving to another platform and using a Samba share to modify the files.

目的是确保我们没有任何Win32特定模块需要加载(即使有条件地加载).

The intent is to ensure we do not have any Win32 specific modules that need to be loaded (even conditionally).

推荐答案

Perl将文件名视为不透明的字节串.它们需要按照您的区域设置"的编码进行编码(ANSI代码页).

Perl treats file names as opaque strings of bytes. They need to be encoded as per your "locale"'s encoding (ANSI code page).

在Windows中,通常为cp1252.它由GetACP系统调用返回. (添加"cp").但是,cp1252不支持日语字符.

In Windows, this is is usually cp1252. It is returned by the GetACP system call. (Prepend "cp"). However, cp1252 doesn't support Japanese characters.

Windows还提供了"Unicode"(又名"Wide")界面,但是Perl不提供使用内置工具访问它的权限.但是,您可以使用Win32API :: File的CreateFileW. IIRC,您仍然需要自己对文件名进行编码.如果是这样,您将使用UTF-16le作为编码.

Windows also provides a "Unicode" aka "Wide" interface, but Perl doesn't provide access to it using builtins*. You can use Win32API::File's CreateFileW, though. IIRC, you need to still need to encode the file name yourself. If so, you'd use UTF-16le as the encoding.

*— Perl对Windows的支持在某些方面很糟糕.

* — Perl's support for Windows sucks in some respects.

这篇关于如何使用Perl在Windows中创建Unicode文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆