Windows上的Perl:编码问题 [英] Perl on Windows: Problems with Encoding

查看:165
本文介绍了Windows上的Perl:编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Perl脚本有问题。在类UNIX系统中,它将所有Unicode字符(如ä)正确打印到控制台。在Windows命令行中,字符被破坏为无意义的字形。有没有一个简单的方法来避免这个?我使用使用utf8;



提前感谢

解决方案

使用utf8; 简单地告诉Perl你的源码是使用UTF-8编码的。



它不是在unix上工作。有些字符串将无法正确打印( print chr(0xE9); ),大多数字符串将打印宽字符警告( print chr(0x2660); )。您需要解码输入并编码输出。



在unix系统中,这是usuaully

 code> use open':std',':encoding(UTF-8)'; 

在Windows系统中,您需要使用 chcp 找到控制台的字符页。 (437 for me。)

  use open':std',':encoding(cp437)'; #控制台
使用的编码使用打开IO => :编码(CP1252); #文件使用的编码


I have a problem with my Perl scripts. In UNIX-like systems it prints out all Unicode characters like ä properly to the console. In the Windows commandline, the characters are broken to senseless glyphs. Is there a simple way to avoid this? I'm using use utf8;.

Thanks in advance.

解决方案

use utf8; simply tells Perl your source is encoded using UTF-8.

It's not working on unix either. There are some strings that won't print properly (print chr(0xE9);), and most that do will print a "Wide character" warning (print chr(0x2660);). You need decode your inputs and encode your outputs.

In unix systems, that's usuaully

use open ':std', ':encoding(UTF-8)';

In Windows system, you'll need to use chcp to find the console's character page. (437 for me.)

use open ':std', ':encoding(cp437)';  # Encoding used by console
use open IO => ':encoding(cp1252)';   # Encoding used by files

这篇关于Windows上的Perl:编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆