在perl中使用API​​粘贴UTF-8

前端之家收集整理的这篇文章主要介绍了在perl中使用API​​粘贴UTF-8前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有点新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处理的差异......

猜你在找的Perl相关文章