.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PERLTW 1" .TH PERLTW 1 2023-11-30 "perl v5.38.2" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME perltw \- 正體中文 Perl 指南 .SH DESCRIPTION .IX Header "DESCRIPTION" 歡迎來到 Perl 的天地! .PP 從 5.8.0 版開始, Perl 具備了完善的 Unicode (萬國碼) 支援, 也連帶支援了許多拉丁語系以外的編碼方式; CJK (中日韓) 便是其中的一部份. Unicode 是國際性的標準, 試圖涵蓋世界上所有的字符: 西方世界, 東方世界, 以及兩者間的一切 (希臘文, 敘利亞文, 阿拉伯文, 希伯來文, 印度文, 印地安文, 等等). 它也容納了多種作業系統與平臺 (如 PC 及麥金塔). .PP Perl 本身以 Unicode 進行操作. 這表示 Perl 內部的字串資料可用 Unicode 表示; Perl 的函式與算符 (例如正規表示式比對) 也能對 Unicode 進行操作. 在輸入及輸出時, 為了處理以 Unicode 之前的編碼方式儲存的資料, Perl 提供了 Encode 這個模組, 可以讓你輕易地讀取及寫入舊有的編碼資料. .PP Encode 延伸模組支援下列正體中文的編碼方式 ('big5' 表示 'big5\-eten'): .PP .Vb 3 \& big5\-eten Big5 編碼 (含倚天延伸字形) \& big5\-hkscs Big5 + 香港外字集, 2001 年版 \& cp950 字碼頁 950 (Big5 + 微軟添加的字符) .Ve .PP 舉例來說, 將 Big5 編碼的檔案轉成 Unicode, 祗需鍵入下列指令: .PP .Vb 2 \& perl \-MEncode \-pe \*(Aq$_= encode( utf8 => decode( big5 => $_ ) )\*(Aq \e \& < file.big5 > file.utf8 .Ve .PP Perl 也內附了 "piconv", 一支完全以 Perl 寫成的字符轉換工具程式, 用法如下: .PP .Vb 2 \& piconv \-f big5 \-t utf8 < file.big5 > file.utf8 \& piconv \-f utf8 \-t big5 < file.utf8 > file.big5 .Ve .PP 另外,若程式碼本身以 utf8 編碼儲存,配合使用 utf8 模組,可讓程式碼中字串以及其運 算皆以字符為單位,而不以位元為單位,如下所示: .PP .Vb 4 \& #!/usr/bin/env perl \& use utf8; \& print length("駱駝"); # 2 (不是 6) \& print index("諄諄教誨", "教誨"); # 2 (從 0 起算第 2 個字符) .Ve .SS 額外的中文編碼 .IX Subsection "額外的中文編碼" 如果需要更多的中文編碼, 可以從 CPAN () 下載 Encode::HanExtra 模組. 它目前提供下列編碼方式: .PP .Vb 4 \& cccii 1980 年文建會的中文資訊交換碼 \& euc\-tw Unix 延伸字符集, 包含 CNS11643 平面 1\-7 \& big5plus 中文數位化技術推廣基金會的 Big5+ \& big5ext 中文數位化技術推廣基金會的 Big5e .Ve .PP 另外, Encode::HanConvert 模組則提供了簡繁轉換用的兩種編碼: .PP .Vb 2 \& big5\-simp Big5 正體中文與 Unicode 簡體中文互轉 \& gbk\-trad GBK 簡體中文與 Unicode 正體中文互轉 .Ve .PP 若想在 GBK 與 Big5 之間互轉, 請參考該模組內附的 b2g.pl 與 g2b.pl 兩支程式, 或在程式內使用下列寫法: .PP .Vb 3 \& use Encode::HanConvert; \& $euc_cn = big5_to_gb($big5); # 從 Big5 轉為 GBK \& $big5 = gb_to_big5($euc_cn); # 從 GBK 轉為 Big5 .Ve .SS 進一步的資訊 .IX Subsection "進一步的資訊" 請參考 Perl 內附的大量說明文件 (不幸全是用英文寫的), 來學習更多關於 Perl 的知識, 以及 Unicode 的使用方式. 不過, 外部的資源相當豐富: .SS "提供 Perl 資源的網址" .IX Subsection "提供 Perl 資源的網址" .IP 4 .IX Item "" Perl 的首頁 .IP 4 .IX Item "" 由 Perl 基金會所營運的文章輯錄 .IP 4 .IX Item "" Perl 綜合典藏網 (Comprehensive Perl Archive Network) .IP 4 .IX Item "" Perl 郵遞論壇一覽 .SS "學習 Perl 的網址" .IX Subsection "學習 Perl 的網址" .IP 4 .IX Item "" 正體中文版的歐萊禮 Perl 書藉 .SS "Perl 使用者集會" .IX Subsection "Perl 使用者集會" .IP 4 .IX Item "" 臺灣 Perl 推廣組一覽 .IP 4 .IX Item "" Perl.tw 線上聊天室 .SS "Unicode 相關網址" .IX Subsection "Unicode 相關網址" .IP 4 .IX Item "" Unicode 學術學會 (Unicode 標準的制定者) .IP 4 .IX Item "" Unix/Linux 上的 UTF\-8 及 Unicode 答客問 .SS 中文化資訊 .IX Subsection "中文化資訊" .IP 中文化軟體聯盟 4 .IX Item "中文化軟體聯盟" .SH "SEE ALSO" .IX Header "SEE ALSO" Encode, Encode::TW, perluniintro, perlunicode .SH AUTHORS .IX Header "AUTHORS" Jarkko Hietaniemi .PP Audrey Tang (唐鳳)