开发者

Stuck with UTF-8 using API in perl

开发者 https://www.devze.com 2023-03-07 18:36 出处:网络
Kinda new to Perl. I am using Perl web API to开发者_运维百科 get the data. The error is \"application/xml; charset=UTF-8\". I used \'use utf8\' but doesn\'t seem to work. The line it gets stuck looks

Kinda new to Perl. I am using Perl web API to开发者_运维百科 get the data. The error is "application/xml; charset=UTF-8". I used 'use utf8' but doesn't seem to work. The line it gets stuck looks something like this

my @candidates = $c->bookmarks_for(start => 1, tag =>'pubmed');

Can you please help me.

Thank you, Sammed


The

use utf8;

is only (and only) for one thing. When you will use in your source code utf8 characters. For example:

my $utf8str = "αΩ";

For any other thins, for example:

my $data = MyModule::get_some_data();

you should use

my $utf8data = Encode::decode_utf8($data);

In the case, when your get_some_data returning octets (bytes).

For example, when reading text files, you can tell perl utf8 conversion at IO level with,

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.

Or you can use the open pragma for telling perl using utf8 as default at IO layer

use open(:std :utf8);

Here is no short answer. You really should read:

  • 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 is extremely strong in utf8 processing, but you must know, hot to use it properly - unfortunately, here is no shorter way as RTFM...

And note: here are differences in utf8 processing in perl <5.6, 5.6, 5.8, 5.12, 5.14...

0

精彩评论

暂无评论...
验证码 换一张
取 消