內容

名稱

perlunicook - Perl 中處理 Unicode 的食譜範例

說明

此手冊頁包含簡短食譜,展示如何在 Perl 中處理常見的 Unicode 作業,以及最後一個完整的程式。個別食譜中未宣告的變數假設先前已設定為適當的值。

範例

℞ 0:標準開頭

除非另有註明,以下所有範例都需要此標準開頭才能正確運作,並調整 #! 以配合您的系統

#!/usr/bin/env perl

use v5.36;     # or later to get "unicode_strings" feature,
               #   plus strict, warnings
use utf8;      # so literals and identifiers can be in UTF-8
use warnings  qw(FATAL utf8);    # fatalize encoding glitches
use open      qw(:std :encoding(UTF-8)); # undeclared streams in UTF-8
use charnames qw(:full :short);  # unneeded in v5.16

確實讓 Unix 程式設計師也對二進位串流進行 binmode,或使用 :raw 開啟它們,但這是唯一可攜式取得它們的方式。

警告use autodie(2.26 之前)和 use open 彼此不兼容。

℞ 1:通用 Unicode 識別濾鏡

在輸入時總是分解,然後在輸出時重新組合。

use Unicode::Normalize;

while (<>) {
    $_ = NFD($_);   # decompose + reorder canonically
    ...
} continue {
    print NFC($_);  # recompose (where possible) + reorder canonically
}

℞ 2:微調 Unicode 警告

從 v5.14 開始,Perl 區分三種類型的 UTF-8 警告。

use v5.14;                  # subwarnings unavailable any earlier
no warnings "nonchar";      # the 66 forbidden non-characters
no warnings "surrogate";    # UTF-16/CESU-8 nonsense
no warnings "non_unicode";  # for codepoints over 0x10_FFFF

℞ 3:宣告來源為識別碼和文字的 utf8

沒有至關重要的 use utf8 宣告,在文字和識別碼中放入 UTF-8 無法正確運作。如果您使用上面給出的標準開頭,這已經發生了。如果您這樣做,您可以執行類似這樣的操作

use utf8;

my $measure   = "Ångström";
my @μsoft     = qw( cp852 cp1251 cp1252 );
my @ὑπέρμεγας = qw( ὑπέρ  μεγας );
my @鯉        = qw( koi8-f koi8-u koi8-r );
my $motto     = "👪 💗 🐪"; # FAMILY, GROWING HEART, DROMEDARY CAMEL

如果您忘記 use utf8,高位元組將被誤認為是獨立字元,而且什麼都無法正確運作。

℞ 4:字元及其數字

ordchr 函數透明地作用於所有碼點,不僅僅是 ASCII,事實上,甚至不僅僅是 Unicode。

# ASCII characters
ord("A")
chr(65)

# characters from the Basic Multilingual Plane
ord("Σ")
chr(0x3A3)

# beyond the BMP
ord("𝑛")               # MATHEMATICAL ITALIC SMALL N
chr(0x1D45B)

# beyond Unicode! (up to MAXINT)
ord("\x{20_0000}")
chr(0x20_0000)

℞ 5:依字元編號指定 Unicode 文字

在插值文字中,無論是雙引號字串或正規表示式,您都可以使用 \x{HHHHHH} 逸出字元,依其編號指定字元。

String: "\x{3a3}"
Regex:  /\x{3a3}/

String: "\x{1d45b}"
Regex:  /\x{1d45b}/

# even non-BMP ranges in regex work fine
/[\x{1D434}-\x{1D467}]/

℞ 6:依編號取得字元名稱

use charnames ();
my $name = charnames::viacode(0x03A3);

℞ 7:依名稱取得字元編號

use charnames ();
my $number = charnames::vianame("GREEK CAPITAL LETTER SIGMA");

℞ 8:Unicode 命名字元

使用 \N{charname} 符號,在插值文字(雙引號字串和正規表示式)中,依名稱取得字元。在 v5.16 中,有一個隱含的

use charnames qw(:full :short);

但在 v5.16 之前,您必須明確指定您要哪一組字元名稱。:full 名稱是官方 Unicode 字元名稱、別名或序列,它們都共用一個名稱空間。

use charnames qw(:full :short latin greek);

"\N{MATHEMATICAL ITALIC SMALL N}"      # :full
"\N{GREEK CAPITAL LETTER SIGMA}"       # :full

其他任何名稱都是 Perl 特有的便利簡寫。如果您想要特定於腳本的簡短名稱,請按名稱指定一個或多個腳本。

"\N{Greek:Sigma}"                      # :short
"\N{ae}"                               #  latin
"\N{epsilon}"                          #  greek

v5.16 版本還支援 :loose 匯入,用於字元名稱的寬鬆比對,其運作方式就像屬性名稱的寬鬆比對:它會忽略大小寫、空白和底線

"\N{euro sign}"                        # :loose (from v5.16)

從 v5.32 開始,您也可以使用

qr/\p{name=euro sign}/

在正規表示式中取得官方 Unicode 命名字元。這些字元總是進行寬鬆比對。

℞ 9:Unicode 命名序列

這些看起來就像字元名稱,但會傳回多個碼點。請注意 printf 中的 %vx 向量列印功能。

use charnames qw(:full);
my $seq = "\N{LATIN CAPITAL LETTER A WITH MACRON AND GRAVE}";
printf "U+%v04X\n", $seq;
U+0100.0300

℞ 10:自訂命名字元

使用 :alias 為現有字元提供您自己的詞法範圍別名,甚至為未命名私人使用字元提供有用的名稱。

use charnames ":full", ":alias" => {
    ecute => "LATIN SMALL LETTER E WITH ACUTE",
    "APPLE LOGO" => 0xF8FF, # private use character
};

"\N{ecute}"
"\N{APPLE LOGO}"

℞ 11:中日韓碼點名稱

像「東京」這樣的漢字會以字元名稱 CJK UNIFIED IDEOGRAPH-6771CJK UNIFIED IDEOGRAPH-4EAC 回傳,因為它們的「名稱」不同。CPAN Unicode::Unihan 模組有一個大型資料庫可以解碼這些字元(以及更多),只要你知道如何理解它的輸出。

# cpan -i Unicode::Unihan
use Unicode::Unihan;
my $str = "東京";
my $unhan = Unicode::Unihan->new;
for my $lang (qw(Mandarin Cantonese Korean JapaneseOn JapaneseKun)) {
    printf "CJK $str in %-12s is ", $lang;
    say $unhan->$lang($str);
}

列印

CJK 東京 in Mandarin     is DONG1JING1
CJK 東京 in Cantonese    is dung1ging1
CJK 東京 in Korean       is TONGKYENG
CJK 東京 in JapaneseOn   is TOUKYOU KEI KIN
CJK 東京 in JapaneseKun  is HIGASHI AZUMAMIYAKO

如果你腦中有特定的羅馬化方案,請使用特定模組

# cpan -i Lingua::JA::Romanize::Japanese
use Lingua::JA::Romanize::Japanese;
my $k2r = Lingua::JA::Romanize::Japanese->new;
my $str = "東京";
say "Japanese for $str is ", $k2r->chars($str);

列印

Japanese for 東京 is toukyou

℞ 12:明確編碼/解碼

在罕見的情況下,例如資料庫讀取,你可能會收到需要解碼的編碼文字。

 use Encode qw(encode decode);

 my $chars = decode("shiftjis", $bytes, 1);
# OR
 my $bytes = encode("MIME-Header-ISO_2022_JP", $chars, 1);

對於所有編碼都相同的串流,請勿使用編碼/解碼;相反地,請在開啟檔案時設定檔案編碼,或在稍後使用 binmode 設定,如下所述。

℞ 13:將程式引數解碼為 utf8

    $ perl -CA ...
or
    $ export PERL_UNICODE=A
or
   use Encode qw(decode);
   @ARGV = map { decode('UTF-8', $_, 1) } @ARGV;

℞ 14:將程式引數解碼為 locale 編碼

# cpan -i Encode::Locale
use Encode qw(locale);
use Encode::Locale;

# use "locale" as an arg to encode/decode
@ARGV = map { decode(locale => $_, 1) } @ARGV;

℞ 15:宣告 STD{IN,OUT,ERR} 為 utf8

使用命令列選項、環境變數,或明確呼叫 binmode

    $ perl -CS ...
or
    $ export PERL_UNICODE=S
or
    use open qw(:std :encoding(UTF-8));
or
    binmode(STDIN,  ":encoding(UTF-8)");
    binmode(STDOUT, ":utf8");
    binmode(STDERR, ":utf8");

℞ 16:宣告 STD{IN,OUT,ERR} 為 locale 編碼

# cpan -i Encode::Locale
use Encode;
use Encode::Locale;

# or as a stream for binmode or open
binmode STDIN,  ":encoding(console_in)"  if -t STDIN;
binmode STDOUT, ":encoding(console_out)" if -t STDOUT;
binmode STDERR, ":encoding(console_out)" if -t STDERR;

℞ 17:讓檔案 I/O 預設為 utf8

未帶編碼引數開啟的檔案將會是 UTF-8

    $ perl -CD ...
or
    $ export PERL_UNICODE=D
or
    use open qw(:encoding(UTF-8));

℞ 18:讓所有 I/O 和引數預設為 utf8

    $ perl -CSDA ...
or
    $ export PERL_UNICODE=SDA
or
    use open qw(:std :encoding(UTF-8));
    use Encode qw(decode);
    @ARGV = map { decode('UTF-8', $_, 1) } @ARGV;

℞ 19:以特定編碼開啟檔案

指定串流編碼。這是處理編碼文字的正常方式,而不是呼叫低階函式。

# input file
    open(my $in_file, "< :encoding(UTF-16)", "wintext");
OR
    open(my $in_file, "<", "wintext");
    binmode($in_file, ":encoding(UTF-16)");
THEN
    my $line = <$in_file>;

# output file
    open($out_file, "> :encoding(cp1252)", "wintext");
OR
    open(my $out_file, ">", "wintext");
    binmode($out_file, ":encoding(cp1252)");
THEN
    print $out_file "some text\n";

這裡可以指定比編碼更多層級。例如,咒語 ":raw :encoding(UTF-16LE) :crlf" 包含隱含的 CRLF 處理。

℞ 20:Unicode 大小寫

Unicode 大小寫與 ASCII 大小寫非常不同。

uc("henry ⅷ")  # "HENRY Ⅷ"
uc("tschüß")   # "TSCHÜSS"  notice ß => SS

# both are true:
"tschüß"  =~ /TSCHÜSS/i   # notice ß => SS
"Σίσυφος" =~ /ΣΊΣΥΦΟΣ/i   # notice Σ,σ,ς sameness

℞ 21:Unicode 不分大小寫的比較

在 CPAN Unicode::CaseFold 模組中也可用,v5.16 中新的 fc「foldcase」函式授予與 /i 模式修改器始終使用的相同 Unicode 折疊大小寫的存取權

use feature "fc"; # fc() function is from v5.16

# sort case-insensitively
my @sorted = sort { fc($a) cmp fc($b) } @list;

# both are true:
fc("tschüß")  eq fc("TSCHÜSS")
fc("Σίσυφος") eq fc("ΣΊΣΥΦΟΣ")

℞ 22:在正規表示式中比對 Unicode 換行序列

Unicode 換行會比對兩個字元的 CRLF 詞形或任何七個垂直空白字元。這對於處理來自不同作業系統的文字檔很有用。

\R

s/\R/\n/g;  # normalize all linebreaks to \n

℞ 23:取得字元類別

找出數字碼點的一般類別。

use Unicode::UCD qw(charinfo);
my $cat = charinfo(0x3A3)->{category};  # "Lu"

℞ 24:停用內建字元類別中的 Unicode 辨識

停用 \w\b\s\d 和 POSIX 類別在 Unicode 中正確運作,無論是在此範圍內或只在一個正規表示式中。

use v5.14;
use re "/a";

# OR

my($num) = $str =~ /(\d+)/a;

或使用特定的非 Unicode 屬性,例如 \p{ahex}\p{POSIX_Digit}。無論應套用什麼字元集修改器 (/d /u /l /a /aa),屬性仍會正常運作。

℞ 25:在正規表示式中使用 \p、\P 比對 Unicode 屬性

這些全部會比對具備指定屬性的單一碼點。使用 \P 取代 \p 以比對缺少該屬性的單一碼點。

\pL, \pN, \pS, \pP, \pM, \pZ, \pC
\p{Sk}, \p{Ps}, \p{Lt}
\p{alpha}, \p{upper}, \p{lower}
\p{Latin}, \p{Greek}
\p{script_extensions=Latin}, \p{scx=Greek}
\p{East_Asian_Width=Wide}, \p{EA=W}
\p{Line_Break=Hyphen}, \p{LB=HY}
\p{Numeric_Value=4}, \p{NV=4}

℞ 26:自訂字元屬性

在編譯時定義您自己的自訂字元屬性,以用於正規表示式中。

# using private-use characters
sub In_Tengwar { "E000\tE07F\n" }

if (/\p{In_Tengwar}/) { ... }

# blending existing properties
sub Is_GraecoRoman_Title {<<'END_OF_SET'}
+utf8::IsLatin
+utf8::IsGreek
&utf8::IsTitle
END_OF_SET

if (/\p{Is_GraecoRoman_Title}/ { ... }

℞ 27:Unicode 正規化

通常在輸入時轉換為 NFD,在輸出時轉換為 NFC。使用 NFKC 或 NFKD 函式可提升搜尋的召回率,假設您已對要搜尋的相同文字執行相同操作。請注意,這不僅僅是預先組合相容性字形;它還會根據其標準組合類別重新排列標記,並清除單例。

use Unicode::Normalize;
my $nfd  = NFD($orig);
my $nfc  = NFC($orig);
my $nfkd = NFKD($orig);
my $nfkc = NFKC($orig);

℞ 28:轉換非 ASCII Unicode 數字

除非您使用 /a/aa,否則 \d 不僅會比對 ASCII 數字,但 Perl 的隱式字串轉數字轉換目前無法辨識這些數字。以下是手動轉換此類字串的方法。

use v5.14;  # needed for num() function
use Unicode::UCD qw(num);
my $str = "got Ⅻ and ४५६७ and ⅞ and here";
my @nums = ();
while ($str =~ /(\d+|\N)/g) {  # not just ASCII!
   push @nums, num($1);
}
say "@nums";   #     12      4567      0.875

use charnames qw(:full);
my $nv = num("\N{RUMI DIGIT ONE}\N{RUMI DIGIT TWO}");

℞ 29:在正規表示式中比對 Unicode 字形叢集

程式設計師可見的「字元」是 /./s 比對的碼點,但使用者可見的「字元」是 /\X/ 比對的字形。

# Find vowel *plus* any combining diacritics,underlining,etc.
my $nfd = NFD($orig);
$nfd =~ / (?=[aeiou]) \X /xi

℞ 30: 使用字元而非碼點進行萃取 (regex)

# match and grab five first graphemes
my($first_five) = $str =~ /^ ( \X{5} ) /x;

℞ 31: 使用字元而非碼點進行萃取 (substr)

# cpan -i Unicode::GCString
use Unicode::GCString;
my $gcs = Unicode::GCString->new($str);
my $first_five = $gcs->substr(0, 5);

℞ 32: 使用字元反轉字串

使用碼點反轉會搞亂變音符號,錯誤地將 crème brûlée 轉換成 éel̂urb em̀erc 而不是 eélûrb emèrc;因此改用字元反轉。無論字串使用哪種正規化,這兩種方法都能正確運作

$str = join("", reverse $str =~ /\X/g);

# OR: cpan -i Unicode::GCString
use Unicode::GCString;
$str = reverse Unicode::GCString->new($str);

℞ 33: 字串長度(以字元為單位)

字串 brûlée 有六個字元,但有八個碼點。這是以字元計算,而不是以碼點計算

my $str = "brûlée";
my $count = 0;
while ($str =~ /\X/g) { $count++ }

 # OR: cpan -i Unicode::GCString
use Unicode::GCString;
my $gcs = Unicode::GCString->new($str);
my $count = $gcs->length;

℞ 34: Unicode 列寬(用於列印)

Perl 的 printfsprintfformat 認為所有碼點都佔用 1 個列印欄位,但許多碼點佔用 0 或 2 個欄位。為了顯示正規化沒有影響,我們列印出兩種形式

use Unicode::GCString;
use Unicode::Normalize;

my @words = qw/crème brûlée/;
@words = map { NFC($_), NFD($_) } @words;

for my $str (@words) {
    my $gcs = Unicode::GCString->new($str);
    my $cols = $gcs->columns;
    my $pad = " " x (10 - $cols);
    say str, $pad, " |";
}

產生此結果,顯示無論正規化如何,它都能正確填充

crème      |
crème      |
brûlée     |
brûlée     |

℞ 35: Unicode 校對

依據數字碼點排序的文字不會遵循合理的字母順序;請使用 UCA 排序文字。

use Unicode::Collate;
my $col = Unicode::Collate->new();
my @list = $col->sort(@old_list);

請參閱 Unicode::Tussle CPAN 模組中的 ucsort 程式,以取得這個模組的便利命令列介面。

℞ 36: 大小寫 重音不敏感的 Unicode 排序

指定校對強度為等級 1,以忽略大小寫和變音符號,只查看基本字元。

use Unicode::Collate;
my $col = Unicode::Collate->new(level => 1);
my @list = $col->sort(@old_list);

℞ 37: Unicode 地區設定校對

有些地區設定有特殊的排序規則。

# either use v5.12, OR: cpan -i Unicode::Collate::Locale
use Unicode::Collate::Locale;
my $col = Unicode::Collate::Locale->new(locale => "de__phonebook");
my @list = $col->sort(@old_list);

上面提到的 ucsort 程式接受 --locale 參數。

℞ 38: 讓 cmp 在文字上運作,而不是在碼點上運作

不要這樣做

@srecs = sort {
    $b->{AGE}   <=>  $a->{AGE}
                ||
    $a->{NAME}  cmp  $b->{NAME}
} @recs;

這樣做

my $coll = Unicode::Collate->new();
for my $rec (@recs) {
    $rec->{NAME_key} = $coll->getSortKey( $rec->{NAME} );
}
@srecs = sort {
    $b->{AGE}       <=>  $a->{AGE}
                    ||
    $a->{NAME_key}  cmp  $b->{NAME_key}
} @recs;

℞ 39: 大小寫 重音不敏感的比較

使用一個校對物件來比較 Unicode 文字,以字元為單位,而不是以編碼點為單位。

use Unicode::Collate;
my $es = Unicode::Collate->new(
    level => 1,
    normalization => undef
);

 # now both are true:
$es->eq("García",  "GARCIA" );
$es->eq("Márquez", "MARQUEZ");

℞ 40:大小寫 重音不敏感的區域設定比較

相同,但位於特定區域設定中。

my $de = Unicode::Collate::Locale->new(
           locale => "de__phonebook",
         );

# now this is true:
$de->eq("tschüß", "TSCHUESS");  # notice ü => UE, ß => SS

℞ 41:Unicode 換行

根據 Unicode 規則將文字分成數行。

# cpan -i Unicode::LineBreak
use Unicode::LineBreak;
use charnames qw(:full);

my $para = "This is a super\N{HYPHEN}long string. " x 20;
my $fmt = Unicode::LineBreak->new;
print $fmt->break($para), "\n";

℞ 42:Unicode 文字在 DBM hash 中,繁瑣的方式

如果任何編碼點不符合位元組,則使用正規 Perl 字串作為 DBM hash 的鍵或值會觸發寬字元例外。以下是手動管理轉換的方法

   use DB_File;
   use Encode qw(encode decode);
   tie %dbhash, "DB_File", "pathname";

# STORE

   # assume $uni_key and $uni_value are abstract Unicode strings
   my $enc_key   = encode("UTF-8", $uni_key, 1);
   my $enc_value = encode("UTF-8", $uni_value, 1);
   $dbhash{$enc_key} = $enc_value;

# FETCH

   # assume $uni_key holds a normal Perl string (abstract Unicode)
   my $enc_key   = encode("UTF-8", $uni_key, 1);
   my $enc_value = $dbhash{$enc_key};
   my $uni_value = decode("UTF-8", $enc_value, 1);

℞ 43:Unicode 文字在 DBM hash 中,簡單的方式

以下是隱式管理轉換的方法;所有編碼和解碼都是自動完成的,就像附加了特定編碼的串流一樣

   use DB_File;
   use DBM_Filter;

   my $dbobj = tie %dbhash, "DB_File", "pathname";
   $dbobj->Filter_Value("utf8");  # this is the magic bit

# STORE

   # assume $uni_key and $uni_value are abstract Unicode strings
   $dbhash{$uni_key} = $uni_value;

 # FETCH

   # $uni_key holds a normal Perl string (abstract Unicode)
   my $uni_value = $dbhash{$uni_key};

℞ 44:程式:Unicode 校對和列印示範

以下是一個完整的程式,展示如何利用區域設定敏感的排序、Unicode 大小寫,以及在某些字元佔用零或兩個欄位(而非每次只佔一個欄位)時管理列印寬度。執行時,以下程式會產生整齊對齊的輸出

Crème Brûlée....... €2.00
Éclair............. €1.60
Fideuà............. €4.20
Hamburger.......... €6.00
Jamón Serrano...... €4.45
Linguiça........... €7.00
Pâté............... €4.15
Pears.............. €2.00
Pêches............. €2.25
Smørbrød........... €5.75
Spätzle............ €5.50
Xoriço............. €3.00
Γύρος.............. €6.50
막걸리............. €4.00
おもち............. €2.65
お好み焼き......... €8.00
シュークリーム..... €1.85
寿司............... €9.99
包子............... €7.50

以下是該程式。

#!/usr/bin/env perl
# umenu - demo sorting and printing of Unicode food
#
# (obligatory and increasingly long preamble)
#
use v5.36;
use utf8;
use warnings  qw(FATAL utf8);    # fatalize encoding faults
use open      qw(:std :encoding(UTF-8)); # undeclared streams in UTF-8
use charnames qw(:full :short);  # unneeded in v5.16

# std modules
use Unicode::Normalize;          # std perl distro as of v5.8
use List::Util qw(max);          # std perl distro as of v5.10
use Unicode::Collate::Locale;    # std perl distro as of v5.14

# cpan modules
use Unicode::GCString;           # from CPAN

my %price = (
    "γύρος"             => 6.50, # gyros
    "pears"             => 2.00, # like um, pears
    "linguiça"          => 7.00, # spicy sausage, Portuguese
    "xoriço"            => 3.00, # chorizo sausage, Catalan
    "hamburger"         => 6.00, # burgermeister meisterburger
    "éclair"            => 1.60, # dessert, French
    "smørbrød"          => 5.75, # sandwiches, Norwegian
    "spätzle"           => 5.50, # Bayerisch noodles, little sparrows
    "包子"              => 7.50, # bao1 zi5, steamed pork buns, Mandarin
    "jamón serrano"     => 4.45, # country ham, Spanish
    "pêches"            => 2.25, # peaches, French
    "シュークリーム"    => 1.85, # cream-filled pastry like eclair
    "막걸리"            => 4.00, # makgeolli, Korean rice wine
    "寿司"              => 9.99, # sushi, Japanese
    "おもち"            => 2.65, # omochi, rice cakes, Japanese
    "crème brûlée"      => 2.00, # crema catalana
    "fideuà"            => 4.20, # more noodles, Valencian
                                 # (Catalan=fideuada)
    "pâté"              => 4.15, # gooseliver paste, French
    "お好み焼き"        => 8.00, # okonomiyaki, Japanese
);

my $width = 5 + max map { colwidth($_) } keys %price;

# So the Asian stuff comes out in an order that someone
# who reads those scripts won't freak out over; the
# CJK stuff will be in JIS X 0208 order that way.
my $coll  = Unicode::Collate::Locale->new(locale => "ja");

for my $item ($coll->sort(keys %price)) {
    print pad(entitle($item), $width, ".");
    printf " €%.2f\n", $price{$item};
}

sub pad ($str, $width, $padchar) {
    return $str . ($padchar x ($width - colwidth($str)));
}

sub colwidth ($str) {
    return Unicode::GCString->new($str)->columns;
}

sub entitle ($str) {
    $str =~ s{ (?=\pL)(\S)     (\S*) }
             { ucfirst($1) . lc($2)  }xge;
    return $str;
}

另請參閱

請參閱下列手冊頁,其中一些是 CPAN 模組:perlunicodeperlunipropsperlreperlrecharclassperluniintroperlunitutperlunifaqPerlIODB_FileDBM_FilterDBM_Filter::utf8EncodeEncode::LocaleUnicode::UCDUnicode::NormalizeUnicode::GCStringUnicode::LineBreakUnicode::CollateUnicode::Collate::LocaleUnicode::UnihanUnicode::CaseFoldUnicode::TussleLingua::JA::Romanize::JapaneseLingua::ZH::Romanize::PinyinLingua::KO::Romanize::Hangul

Unicode::Tussle CPAN 模組包含許多協助處理 Unicode 的程式,包括這些用來完全或部分取代標準工具的程式:以 tcgrep 取代 egrep,以 uniquote 取代 cat -vhexdump,以 uniwc 取代 wc,以 unilook 取代 look,以 unifmt 取代 fmt,以及以 ucsort 取代 sort。若要探索 Unicode 字元名稱和字元屬性,請參閱其 unipropsunicharsuninames 程式。它也提供這些程式,這些程式都是執行 Unicode 相關作業的通用篩選器:unititleunicapsuniwideuninarrowunisupersunisubsnfdnfcnfkdnfkc;以及 uclctc

最後,請參閱已發表的 Unicode 標準(頁碼來自版本 6.0.0),包括這些特定附錄和技術報告

§3.13 預設大小寫演算法,第 113 頁;§4.2 大小寫,第 120-122 頁;大小寫對應,第 166-172 頁,特別是從第 170 頁開始的無大小寫比對。
UAX #44:Unicode 字元資料庫
UTS #18:Unicode 正規表示式
UAX #15:Unicode 正規化形式
UTS #10:Unicode 校對演算法
UAX #29:Unicode 文字分隔
UAX #14:Unicode 換行演算法
UAX #11:東亞文字寬度

作者

Tom Christiansen <tchrist@perl.com> 撰寫此文件,並偶爾在幕後收到 Larry Wall 和 Jeffrey Friedl 的批評。

著作權和授權

著作權所有 © 2012 Tom Christiansen。

此程式為免費軟體;您可以在與 Perl 相同的條款下重新散布或修改它。

這些範例大多取自「駱駝書」的最新版本;亦即取自 Perl 程式設計 第 4 版,著作權所有 © 2012 Tom Christiansen <等人>,2012-02-13 由 O’Reilly Media 出版。程式碼本身可以自由重新散布,我們鼓勵您移植、摺疊、旋轉和修改此說明頁中的任何範例,並將其納入您自己的程式中,而無需承擔任何負擔。透過程式碼註解表示感謝是禮貌的行為,但並非必要。

修訂記錄

v1.0.0 – 第一次公開發行,2012-02-27