2012-01-01 95 views
-2

文件中在Perl中我写串到下面的方式创建一个临时文件的脚本:写非UTF8字符在Perl

IO::File->new_tmpfile 

我怎么能写以同样的方式,非UTF8字符?

+0

那么,只需使用正常的操作与适当的标量......你有没有尝试过,至少?哦,看看'pack()' – fge 2012-01-01 16:35:15

+0

“Non utf8”告诉我们你*不需要*。你想要什么? – 2012-01-01 18:30:15

回答

0

IO::File->new_tmpfile返回一个文件句柄。按照通常的方式,您可以将print添加到文件句柄中。

$fh = IO::File->new_tmpfile; 
print $fh "some stuff to write to the temp file.\n"; 
+0

如果char不是utf8字符,则在打印常规方式时出现“宽字符”错误。 – Shay 2012-01-02 07:54:14

2

IO::File对象有一个binmode方法,工程完全相同的方式作为built-in of the same name相同。您可以使用它来设置所需的I/O层。你可能想要这样的东西:

$fh->binmode(':utf8'); # or whatever character encoding you're using