【发布时间】:2012-01-01 16:25:36
【问题描述】:
在 perl 的脚本中,我将字符串写入以下列方式创建的临时文件:
IO::File->new_tmpfile
如何用同样的方式书写,非 utf8 字符?
【问题讨论】:
-
好吧,只需使用适当标量的正常操作...您至少尝试过吗?哦,看看
pack() -
"Non utf8" 告诉我们您不想要什么。你想要什么?
在 perl 的脚本中,我将字符串写入以下列方式创建的临时文件:
IO::File->new_tmpfile
如何用同样的方式书写,非 utf8 字符?
【问题讨论】:
pack()
您的IO::File 对象有一个binmode 方法,其工作方式与built-in of the same name 完全相同。您可以使用它来设置所需的 I/O 层。你可能想要这样的东西:
$fh->binmode(':utf8'); # or whatever character encoding you're using
【讨论】:
IO::File->new_tmpfile 返回一个文件句柄。您可以像往常一样将print 发送到文件句柄。
$fh = IO::File->new_tmpfile;
print $fh "some stuff to write to the temp file.\n";
【讨论】: