Perl拉丁语9?Unicode - 需要添加支持

Phi*_*ord 2 unicode perl character-encoding latin9

我有一个正在扩展到英国的应用程序,我需要添加对Latin-9 Unicode的支持.我做了一些谷歌搜索,但没有发现该过程涉及的内容是什么.有小费吗?

这是一些代码(只是Unicode的东西)

use Unicode::String qw(utf8 latin1 utf16);

# How to call
$encoded_txt = $self->unicode_encode($item->{value});

# Function part
sub unicode_encode {

    shift() if ref($_[0]);
    my $toencode = shift();
    return undef unless defined($toencode);

    Unicode::String->stringify_as("utf8");
    my $unicode_str = Unicode::String->new();


    # encode Perl UTF-8 string into latin1 Unicode::String
    #  - currently only Basic Latin and Latin 1 Supplement
    #    are supported here due to issues with Unicode::String .
    $unicode_str->latin1( $toencode );
    ...
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒,谢谢.

编辑:我确实找到了这篇文章:http://czyborra.com/charsets/iso8859.html

cjm*_*cjm 5

Unicode :: String很古老,旨在为旧版Perls添加Unicode支持.现代版本的Perl(5.8.0及更高版本)具有本机Unicode支持.查看Encode模块和:encoding层.您可以在Perl中获取支持的编码列表perldoc Encode::Supported.

基本上,您只需要在输入和输出上解码/编码为Latin-9.其余的时间,你应该使用Perl的原生UTF-8字符串.

# Read a Latin-9 file:
open(my $in, '<:encoding(Latin9)', 'some/file');
my $line = <$in>; # Automatically converts Latin9 to UTF-8

# Write a Latin-9 file:
open(my $out, '>:encoding(Latin9)', 'other/file');
print $out $line; # Automatically converts UTF-8 to Latin9
Run Code Online (Sandbox Code Playgroud)

  • Perl 5.6.1现在已经9岁了.(甚至5.6.2几乎是7.)现在是他们升级的时候了.我怀疑为Unicode :: String添加Latin9支持会很困难,但你可能不得不自己动手. (3认同)