加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 23:25:11 所属栏目:大数据 来源:网络整理
导读:有点新Perl.我使用Perl Web API来获取数据.错误是“application / xml; charset = UTF-8”.我使用’use utf8’但似乎不起作用.它被卡住的线看起来像这样 my @candidates = $c-bookmarks_for(start = 1,tag ='pubmed'); 你能帮我么. 谢谢, Sammed 解决方法 该
有点新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处理的差异......

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读