应该始终通过utf8 :: decode对perl的File :: Glob进行后期过滤吗? [英] Should perl's File::Glob always be post-filtered through utf8::decode?

查看:75
本文介绍了应该始终通过utf8 :: decode对perl的File :: Glob进行后期过滤吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下最小示例的输出表明(在我的Linux机器上)File :: Glob似乎具有将utf8字符串转换为非utf8的意外副作用:

#!/usr/bin/perl 

use utf8;

use strict;

my $x = "påminnelser";
my $y = glob $x;

print "x=",utf8::is_utf8($x),"=\n";
print "y=",utf8::is_utf8($y),"=\n";

这导致我的程序出现错误行为.在Linux上,看来我可以在File :: Glob之后应用utf8 :: decode()来修复它.这是解决此问题的正确方法吗?这是File :: Glob中的错误吗?我的修复程序能否在Windows等其他系统上产生正确的结果?

解决方案

目前,在perl的待办事项列表中编码处理文件名的函数:

This is causing wrong behavior in my program. On linux, it looks like I can fix it by applying utf8::decode() after File::Glob. Is this the right way to fix this? Is this a bug in File::Glob? Will my fix produce correct results on other systems such as Windows?

Encoding handling of functions dealing with file names is currently on perl's todo list: Unicode in Filenames. Problem is that some popular operating systems (i.e. Linux) don't have support for file name encoding (other than using the current locale settings, but this is broken by design), so getting a portable solution in Perl is not that easy.

My advice is to avoid non-ASCII file names at all.

这篇关于应该始终通过utf8 :: decode对perl的File :: Glob进行后期过滤吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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