使用带有 unicode 文件名的文件 I/O API 的通用方法是什么?
在 Windows 中,有一个常见问题:文件名在传递给 open()
之前,应将其转换为本地代码页。当然,可以使用 < code>Win32::API 为此,但我不希望我的脚本依赖于平台。目前我必须写一些类似的内容:
open IN, "<", encode("cp1251", $filename) or die $!;
但是有没有任何库可以隐藏这些细节?我认为本地代码页可以自动检测,所以我只想传递 unicode 文件名并忘记细节。为什么它还没在盒子里?
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 $!;
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它过去只能工作到 5.8.1,然后 Jarkko 将其取出,并在顶部进行了无偿的不兼容更改,破坏了
-C
开关。这使得 Windows 成为二等公民,直到今天还让我很恼火,因为任何其他动态语言都没有这种荒谬的缺陷。也许现在是我们可以听到这种更糟的变化的理由的好时机。不管怎样,你想要
PerlIO::fse
,但这不是一个完美的解决方案,您很快就会自己发现。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.Anyway, you want
PerlIO::fse
, but it's not a perfect solution, as you will soon discover on your own.