使用unicode文件名使用文件I / O API的通用方法是什么? [英] What is the universal way to use file I/O API with unicode filenames?

查看:151
本文介绍了使用unicode文件名使用文件I / O API的通用方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中有常见问题 :在传递给 open()之前,文件名应该转换为本地代码页。当然,有可能使用 Win32 :: API ,但我不希望我的脚本是平台相关的。目前我必须写下如下内容:

In Windows there is a common problem: the filenames should be converted to local codepage, before they are passed to open(). Of course, there is a possibility to use Win32::API for that, but I don't want my script to be platform-dependent. At the moment I have to write something like:

open IN, "<", encode("cp1251", $filename) or die $!; 

但是有没有图书馆,隐藏这些细节?我认为本地代码页可以自动检测,所以我只想传递unicode文件名,忘记了细节。为什么它仍然不在框中?

but is there any library, that hides these details? I think the local codepage can be automatically detected, so I just want to pass unicode filename and forget about the details. Why is it still not in the box?

推荐答案

使用 ,然后Jarkko把它拿出来,并在顶部的一个不愉快的不兼容的变化中打破了 -C 开关。这使得Windows成为二等公民,直到今天都让我烦恼,因为任何其他动态语言都没有这个荒谬的缺陷。也许现在是一个好时机,我们可以听到这种变化的理由更糟。

It used to just work until 5.8.1, then Jarkko took it out, and broke the -C switch in an gratutious incompatible change on top. This makes Windows a second class citizen and annoys me until today, because any other dynamic language does not have this ridiculous defect. Perhaps now is a good time that we could hear a justification for this change for the worse.

无论如何,你要 PerlIO :: fse ,但这不是一个完美的解决方案,你很快就会发现。

Anyway, you want PerlIO::fse, but it's not a perfect solution, as you will soon discover on your own.

这篇关于使用unicode文件名使用文件I / O API的通用方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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