Path::Class::Unicode:我是否必须自行检查ufile
和open
是否存在错误,还是自动完成?
use Path::Class::Unicode;
my $file = ufile( "filename" );
my $fh = $file->open;
答案 0 :(得分:1)
ufile
只是该类构造函数的一个wapper,它不应该抛出任何错误。
open
方法是围绕IO::File
(或IO::Dir
的构造函数的wapper)。 new
上的IO::File
方法可能会为无效参数抛出错误,但否则会返回文件句柄或open
,sysopen
的正常返回值等。但是,这由IO::File
包装,以返回有效的文件句柄或undef
。
因此,您应该执行自己的错误处理:
my $fh = $file->open or die "Could not open $filename: $!";
# do not use the stringification of $file, as that would be a byte string
我不确定Path :: Class :: Unicode是否具有显着的优势,考虑到不同的操作系统如何处理unicode文件名。通常最好将文件名视为二进制数据,这是当前open
内置函数的工作方式。