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

标签 perl unicode 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 );
    ...

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

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

最佳答案

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

基本上,您只需在输入和输出上解码/编码为 Latin-9 即可。其余时间,您应该使用 Perl 的 native 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

关于Perl 拉丁语 9? Unicode - 需要添加支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3039600/

相关文章:

php - UTF-8 字符串在某处错误编码

java - 我如何从 Java 调用 Perl?

python - 如何从数据库中收集非结构化数据?

regex - 取消转义字符串中的 unicode

database - Qt query.value 返回错误的字符(字符编码)

c# - 在 C# 中自定义编码 0-31 之间的 ascii 字符

php - 在 linux 中的 bash 的 .sh 之类的脚本中使用 php 和 perl 以及 R 等等?是否可以?

image - 如何轻松地将 rgb 颜色值转换为十六进制颜色值?

c++ - 我如何从 wostream 转换为 ostream

android - AccessibilityService 可以调度关键事件,甚至包括 Unicode 字符吗?