Debian Codegraph @

upstream/opensuse-tumbleweed/man1/perlcn.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 "PERLCN 1"
61 .TH PERLCN 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 perlcn \- 简体中文 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 扩展模块支持下列简体中文的编码方式 (\*(Aqgb2312\*(Aq 表示 \*(Aqeuc\-cn\*(Aq):
84 .PP
85 .Vb 6
86 \& euc\-cn Unix 扩展字符集, 也就是俗称的国标码
87 \& gb2312\-raw 未经处理的 (低比特) GB2312 字符表
88 \& gb12345 未经处理的中国用繁体中文编码
89 \& iso\-ir\-165 GB2312 + GB6345 + GB8565 + 新增字符
90 \& cp936 字码页 936, 也可以用 \*(AqGBK\*(Aq (扩充国标码) 指明
91 \& hz 7 比特逸出式 GB2312 编码
92 .Ve
93 .PP
94 举例来说, 将 EUC\-CN 编码的文件转成 Unicode, 只需输入以下命令:
95 .PP
96 .Vb 1
97 \& perl \-Mencoding=euc\-cn,STDOUT,utf8 \-pe1 < file.euc\-cn > file.utf8
98 .Ve
99 .PP
100 Perl 也内附了 "piconv", 一个完全以 Perl 写成的字符转换工具程序, 用法如下:
101 .PP
102 .Vb 2
103 \& piconv \-f euc\-cn \-t utf8 < file.euc\-cn > file.utf8
104 \& piconv \-f utf8 \-t euc\-cn < file.utf8 > file.euc\-cn
105 .Ve
106 .PP
107 另外, 利用 encoding 模块, 你可以轻易写出以字符为单位的代码, 如下所示:
108 .PP
109 .Vb 7
110 \& #!/usr/bin/env perl
111 \& # 启动 euc\-cn 字串解析; 标准输出入及标准错误都设为 euc\-cn 编码
112 \& use encoding \*(Aqeuc\-cn\*(Aq, STDIN => \*(Aqeuc\-cn\*(Aq, STDOUT => \*(Aqeuc\-cn\*(Aq;
113 \& print length("骆驼"); # 2 (双引号表示字符)
114 \& print length(\*(Aq骆驼\*(Aq); # 4 (单引号表示字节)
115 \& print index("谆谆教诲", "蛔唤"); # \-1 (不包含此子字符串)
116 \& print index(\*(Aq谆谆教诲\*(Aq, \*(Aq蛔唤\*(Aq); # 1 (从第二个字节开始)
117 .Ve
118 .PP
119 在最后一列例子里, "谆" 的第二个字节与 "谆" 的第一个字节结合成 EUC\-CN
120 码的 "蛔"; "谆" 的第二个字节则与 "教" 的第一个字节结合成 "唤".
121 这解决了以前 EUC\-CN 码匹配处理上常见的问题.
122 .SS 额外的中文编码
123 .IX Subsection "额外的中文编码"
124 如果需要更多的中文编码, 可以从 CPAN (<https://www.cpan.org/>) 下载
125 Encode::HanExtra 模块. 它目前提供下列编码方式:
126 .PP
127 .Vb 1
128 \& gb18030 扩充过的国标码, 包含繁体中文
129 .Ve
130 .PP
131 另外, Encode::HanConvert 模块则提供了简繁转换用的两种编码:
132 .PP
133 .Vb 2
134 \& big5\-simp Big5 繁体中文与 Unicode 简体中文互转
135 \& gbk\-trad GBK 简体中文与 Unicode 繁体中文互转
136 .Ve
137 .PP
138 若想在 GBK 与 Big5 之间互转, 请参考该模块内附的 b2g.pl 与 g2b.pl 两个程序,
139 或在程序内使用下列写法:
140 .PP
141 .Vb 3
142 \& use Encode::HanConvert;
143 \& $euc_cn = big5_to_gb($big5); # 从 Big5 转为 GBK
144 \& $big5 = gb_to_big5($euc_cn); # 从 GBK 转为 Big5
145 .Ve
146 .SS 进一步的信息
147 .IX Subsection "进一步的信息"
148 请参考 Perl 内附的大量说明文件 (不幸全是用英文写的), 来学习更多关于
149 Perl 的知识, 以及 Unicode 的使用方式. 不过, 外部的资源相当丰富:
150 .SS "提供 Perl 资源的网址"
151 .IX Subsection "提供 Perl 资源的网址"
152 .IP <https://www.perl.org/> 4
153 .IX Item "<https://www.perl.org/>"
154 .PP
155 Perl 的首页
156 .IP <https://www.perl.com/> 4
157 .IX Item "<https://www.perl.com/>"
158 由 Perl 基金会运营的文章辑录
159 .IP <https://www.cpan.org/> 4
160 .IX Item "<https://www.cpan.org/>"
161 Perl 综合典藏网 (Comprehensive Perl Archive Network)
162 .IP <https://lists.perl.org/> 4
163 .IX Item "<https://lists.perl.org/>"
164 Perl 邮递论坛一览
165 .SS "学习 Perl 的网址"
166 .IX Subsection "学习 Perl 的网址"
167 .IP <http://www.oreilly.com.cn/index.php?func=booklist&cat=68> 4
168 .IX Item "<http://www.oreilly.com.cn/index.php?func=booklist&cat=68>"
169 简体中文版的欧莱礼 Perl 书藉
170 .SS "Perl 使用者集会"
171 .IX Subsection "Perl 使用者集会"
172 .IP <https://www.pm.org/groups/asia.html> 4
173 .IX Item "<https://www.pm.org/groups/asia.html>"
174 中国 Perl 推广组一览
175 .SS "Unicode 相关网址"
176 .IX Subsection "Unicode 相关网址"
177 .IP <https://www.unicode.org/> 4
178 .IX Item "<https://www.unicode.org/>"
179 Unicode 学术学会 (Unicode 标准的制定者)
180 .IP <https://www.cl.cam.ac.uk/%7Emgk25/unicode.html> 4
181 .IX Item "<https://www.cl.cam.ac.uk/%7Emgk25/unicode.html>"
182 Unix/Linux 上的 UTF\-8 及 Unicode 常见问题解答
183 .SH "SEE ALSO"
184 .IX Header "SEE ALSO"
185 Encode, Encode::CN, encoding, perluniintro, perlunicode
186 .SH AUTHORS
187 .IX Header "AUTHORS"
188 Jarkko Hietaniemi <[email protected]>
189 .PP
190 Audrey Tang (唐凤) <[email protected]>
191 .PP
192 Sizhe Zhao <[email protected]>