Perl latin-9? Unicode - need to add support

半城伤御伤魂 提交于 2019-12-02 00:21:18

Unicode::String is ancient, and designed to add Unicode support to older Perls. Modern versions of Perl (5.8.0 and up) have native Unicode support. Look at the Encode module and the :encoding layer. You can get a list of the supported encodings in your Perl with perldoc Encode::Supported.

Basically, you just need to decode/encode to Latin-9 on input & output. The rest of the time, you should use Perl's native UTF-8 strings.

# 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

In perldoc Encode::Supported it's referred to as ISO-8859-15 (!). Here is some heavily trimmed down output from perldoc:

           Lang/Regions  ISO/Other Std.  DOS     Windows Macintosh  Others
       ----------------------------------------------------------------
       Latin9 [4]    iso-8859-15
       ----------------------------------------------------------------

       [4] Nicknamed Latin0; the Euro sign as well as French and Finnish
           letters that are missing from 8859-1 were added.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!