如何在Windows机器上的perl脚本中将Unicode文件转换为ASCII文件
我在 Windows 机器上有一个 Unicode 格式的文件。有没有办法使用perl脚本在Windows机器上将其转换为ASCII格式
它是UTF-16 BOM。
I have a file in Unicode format on a windows machine. Is there any way to convert it to ASCII format on a windows machine using perl script
It's UTF-16 BOM.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Perl open 命令上的编码选项。您可以在打开文件进行读取或写入时指定编码:
如下所示:
Take a look at the encoding option on the Perl open command. You can specify the encoding when opening a file for reading or writing:
It'd be something like this would work:
如果你想将unicode转换为ascii,你必须意识到有些字符是无法转换的,因为它们在ascii中不存在。
如果您可以忍受这一点,您可以尝试以下操作:
如果您没有 autodie,只需删除该行 - 然后您应该使用 a 更改您的打开/关闭语句
如果您有无法转换的字符,您将收到警告在控制台上,您的输出文件将包含例如类似的文本
。
BTW:如果你没有妈妈但知道它是Big Endian(Little Endian),你可以将编码行更改为
或
希望它在Windows 下也能工作。我现在不能尝试。
If you want to convert unicode to ascii, you must be aware that some characters can't be converted, because they just don't exist in ascii.
If you can live with that, you can try this:
If you do not have autodie, just remove that line - you should then change your open/close statements with a
If you have characters that can't be converted, you will get warnings on the console and your output file will have e.g. text like
in it.
BTW: If you don't have a mom but know it is Big Endian (Little Endian), you can change the encoding line to
or
Hope it works under Windows as well. I can't give it a try right now.