【发布时间】:2012-02-03 06:31:13
【问题描述】:
我有一个文件位于 Windows XP 机器上的一个目录中,其中包含丹麦语字符。我使用 Strawberry perl 并想阅读这个文件。以下代码工作正常:
use Win32::Unicode::File;
# Some code left out....
$fname = $mw -> getOpenFile(-filetypes=>$types);
my $fh = Win32::Unicode::File->new;
$fh->open('<', $fname);
getOpenFile 例程来自 Tk。现在由于某种原因,Win32::Unicode::File 有一些我无法忍受的不幸副作用(它会吞噬我的记忆,请参阅"Out of memory" with simple Win32::Unicode::File readline loop and Strawberry Perl)。现在,如果我尝试在没有 Win32::Unicode::File 接口的情况下打开文件,我会发现找不到文件。原因是路径被错误地解释了。我尝试根据Perl: managing path encodings on Windows 转换路径,但由于某种原因不起作用。我应该如何解决这个问题?我尝试了以下方法:
use Encode;
# Some code left out....
$fname = $mw -> getOpenFile(-filetypes=>$types);
my $fh;
open($fh, '<', encode("utf8",$fname,Encode::FB_CROAK));
它不起作用。有什么想法吗?
如果我不清楚,请原谅我。
亲切的问候, 迈克尔
【问题讨论】:
-
我认为您应该使用 UTF16 作为编码。 $fname 在调试器中是什么样子的?
标签: perl unicode character-encoding windows-xp strawberry-perl