Debian Codegraph @

upstream/fedora-44/man1/perltw.1

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "PERLTW 1"
61 .TH PERLTW 1 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 perltw \- 正體中文 Perl 指南
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 歡迎來到 Perl 的天地!
71 .PP
72 從 5.8.0 版開始, Perl 具備了完善的 Unicode (萬國碼) 支援,
73 也連帶支援了許多拉丁語系以外的編碼方式; CJK (中日韓) 便是其中的一部份.
74 Unicode 是國際性的標準, 試圖涵蓋世界上所有的字符: 西方世界, 東方世界,
75 以及兩者間的一切 (希臘文, 敘利亞文, 阿拉伯文, 希伯來文, 印度文,
76 印地安文, 等等). 它也容納了多種作業系統與平臺 (如 PC 及麥金塔).
77 .PP
78 Perl 本身以 Unicode 進行操作. 這表示 Perl 內部的字串資料可用 Unicode
79 表示; Perl 的函式與算符 (例如正規表示式比對) 也能對 Unicode 進行操作.
80 在輸入及輸出時, 為了處理以 Unicode 之前的編碼方式儲存的資料, Perl
81 提供了 Encode 這個模組, 可以讓你輕易地讀取及寫入舊有的編碼資料.
82 .PP
83 Encode 延伸模組支援下列正體中文的編碼方式 (\*(Aqbig5\*(Aq 表示 \*(Aqbig5\-eten\*(Aq):
84 .PP
85 .Vb 3
86 \& big5\-eten Big5 編碼 (含倚天延伸字形)
87 \& big5\-hkscs Big5 + 香港外字集, 2001 年版
88 \& cp950 字碼頁 950 (Big5 + 微軟添加的字符)
89 .Ve
90 .PP
91 舉例來說, 將 Big5 編碼的檔案轉成 Unicode, 祗需鍵入下列指令:
92 .PP
93 .Vb 2
94 \& perl \-MEncode \-pe \*(Aq$_= encode( utf8 => decode( big5 => $_ ) )\*(Aq \e
95 \& < file.big5 > file.utf8
96 .Ve
97 .PP
98 Perl 也內附了 "piconv", 一支完全以 Perl 寫成的字符轉換工具程式, 用法如下:
99 .PP
100 .Vb 2
101 \& piconv \-f big5 \-t utf8 < file.big5 > file.utf8
102 \& piconv \-f utf8 \-t big5 < file.utf8 > file.big5
103 .Ve
104 .PP
105 另外,若程式碼本身以 utf8 編碼儲存,配合使用 utf8 模組,可讓程式碼中字串以及其運
106 算皆以字符為單位,而不以位元為單位,如下所示:
107 .PP
108 .Vb 4
109 \& #!/usr/bin/env perl
110 \& use utf8;
111 \& print length("駱駝"); # 2 (不是 6)
112 \& print index("諄諄教誨", "教誨"); # 2 (從 0 起算第 2 個字符)
113 .Ve
114 .SS 額外的中文編碼
115 .IX Subsection "額外的中文編碼"
116 如果需要更多的中文編碼, 可以從 CPAN (<https://www.cpan.org/>) 下載
117 Encode::HanExtra 模組. 它目前提供下列編碼方式:
118 .PP
119 .Vb 4
120 \& cccii 1980 年文建會的中文資訊交換碼
121 \& euc\-tw Unix 延伸字符集, 包含 CNS11643 平面 1\-7
122 \& big5plus 中文數位化技術推廣基金會的 Big5+
123 \& big5ext 中文數位化技術推廣基金會的 Big5e
124 .Ve
125 .PP
126 另外, Encode::HanConvert 模組則提供了簡繁轉換用的兩種編碼:
127 .PP
128 .Vb 2
129 \& big5\-simp Big5 正體中文與 Unicode 簡體中文互轉
130 \& gbk\-trad GBK 簡體中文與 Unicode 正體中文互轉
131 .Ve
132 .PP
133 若想在 GBK 與 Big5 之間互轉, 請參考該模組內附的 b2g.pl 與 g2b.pl 兩支程式,
134 或在程式內使用下列寫法:
135 .PP
136 .Vb 3
137 \& use Encode::HanConvert;
138 \& $euc_cn = big5_to_gb($big5); # 從 Big5 轉為 GBK
139 \& $big5 = gb_to_big5($euc_cn); # 從 GBK 轉為 Big5
140 .Ve
141 .SS 進一步的資訊
142 .IX Subsection "進一步的資訊"
143 請參考 Perl 內附的大量說明文件 (不幸全是用英文寫的), 來學習更多關於
144 Perl 的知識, 以及 Unicode 的使用方式. 不過, 外部的資源相當豐富:
145 .SS "提供 Perl 資源的網址"
146 .IX Subsection "提供 Perl 資源的網址"
147 .IP <https://www.perl.org/> 4
148 .IX Item "<https://www.perl.org/>"
149 Perl 的首頁
150 .IP <https://www.perl.com/> 4
151 .IX Item "<https://www.perl.com/>"
152 由 Perl 基金會所營運的文章輯錄
153 .IP <https://www.cpan.org/> 4
154 .IX Item "<https://www.cpan.org/>"
155 Perl 綜合典藏網 (Comprehensive Perl Archive Network)
156 .IP <https://lists.perl.org/> 4
157 .IX Item "<https://lists.perl.org/>"
158 Perl 郵遞論壇一覽
159 .SS "學習 Perl 的網址"
160 .IX Subsection "學習 Perl 的網址"
161 .IP <http://www.oreilly.com.cn/index.php?func=booklist&cat=68> 4
162 .IX Item "<http://www.oreilly.com.cn/index.php?func=booklist&cat=68>"
163 正體中文版的歐萊禮 Perl 書藉
164 .SS "Perl 使用者集會"
165 .IX Subsection "Perl 使用者集會"
166 .IP <https://www.pm.org/groups/taiwan.html> 4
167 .IX Item "<https://www.pm.org/groups/taiwan.html>"
168 臺灣 Perl 推廣組一覽
169 .IP <irc://chat.freenode.org/#perl.tw> 4
170 .IX Item "<irc://chat.freenode.org/#perl.tw>"
171 Perl.tw 線上聊天室
172 .SS "Unicode 相關網址"
173 .IX Subsection "Unicode 相關網址"
174 .IP <https://www.unicode.org/> 4
175 .IX Item "<https://www.unicode.org/>"
176 Unicode 學術學會 (Unicode 標準的制定者)
177 .IP <http://www.cl.cam.ac.uk/%7Emgk25/unicode.html> 4
178 .IX Item "<http://www.cl.cam.ac.uk/%7Emgk25/unicode.html>"
179 Unix/Linux 上的 UTF\-8 及 Unicode 答客問
180 .SS 中文化資訊
181 .IX Subsection "中文化資訊"
182 .IP 中文化軟體聯盟 4
183 .IX Item "中文化軟體聯盟"
184 <http://www.cpatch.org/>
185 .SH "SEE ALSO"
186 .IX Header "SEE ALSO"
187 Encode, Encode::TW, perluniintro, perlunicode
188 .SH AUTHORS
189 .IX Header "AUTHORS"
190 Jarkko Hietaniemi <[email protected]>
191 .PP
192 Audrey Tang (唐鳳) <[email protected]>