有点新Perl.我使用Perl Web API来获取数据.错误是“application / xml; charset = UTF-8”.我使用’use utf8’但似乎不起作用.它被卡住的线看起来像这样
my @candidates = $c->bookmarks_for(start => 1,tag =>'pubmed');
你能帮我么.
谢谢,
Sammed
解决方法
该
use utf8;
只有(也是唯一的)一件事.当您在源代码中使用utf8字符时.例如:
my $utf8str = "αΩ";
对于任何其他的,例如:
my $data = MyModule::get_some_data();
你应该使用
my $utf8data = Encode::decode_utf8($data);
在这种情况下,当你的get_some_data返回八位字节(字节)时.
例如,在读取文本文件时,您可以在IO级别告诉perl utf8转换,
open($fd,"<",$filename); $fd->binmode(:utf8); #for marking data as utf8,or $fd->binmode(:encoding(utf8)); #for marking *and* checking data for utf8 validity too.
或者,您可以使用open pragma在IO层使用utf8作为默认值来告诉perl
use open(:std :utf8);
这里没有简短的回答.你真的应该阅读:
> http://perldoc.perl.org/utf8.html
> http://perldoc.perl.org/Encode.html
> http://perldoc.perl.org/perlunicode.html
> http://perldoc.perl.org/perlunifaq.html
> http://perldoc.perl.org/perluniintro.html
> http://perldoc.perl.org/perlunitut.html
Perl在utf8处理方面非常强大,但你必须知道,热门才能正确使用它 – 不幸的是,这里没有像RTFM那样短暂的方式……
请注意:以下是perl< 5.6,5.6,5.8,5.12,5.14中utf8处理的差异......
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。