| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (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 |
.\" |
| 57 |
.IX Title "PERLJP 1" |
| 58 |
.TH PERLJP 1 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
perljp \- 日本語 Perl ガイド |
| 65 |
.SH 説明 |
| 66 |
.IX Header "説明" |
| 67 |
Perl の世界へようこそ! |
| 68 |
.PP |
| 69 |
Perl 5.8.0 より、Unicodeサポートが大幅に強化され、その結果ラテン文字以外の文字コードのサポートが CJK (中国語、日本語、ハングル)を含めて加わりました。Unicodeは世界中の文字を一つの文字コードで扱うことを目指した標準規格であり、東から西、はたまたその間の文字(ギリシャ文字、キリール文字、アラビア文字、ヘブライ文字、ディーヴァナガーリ文字、などなど)や、これまではOSベンダーが独自に定めていた文字(PCおよびMacintosh)がすでに含まれています。 |
| 70 |
.PP |
| 71 |
Perl 自身は Unicode で動作します。Perl スクリプト内の文字列リテラルや正規表現は Unicode を前提としています。そして入出力のためには、これまで使われてきたさまざまな文字コードに対応するモジュール、「 Encode 」が標準装備されており、Unicode とこれらの文字コードの相互変換も簡単に行えるようになっています。 |
| 72 |
.PP |
| 73 |
現時点で Encode がサポートする文字コードは以下のとおりです。 |
| 74 |
.PP |
| 75 |
.Vb 10 |
| 76 |
\& 7bit\-jis AdobeStandardEncoding AdobeSymbol AdobeZdingbat |
| 77 |
\& ascii big5 big5\-hkscs cp1006 |
| 78 |
\& cp1026 cp1047 cp1250 cp1251 |
| 79 |
\& cp1252 cp1253 cp1254 cp1255 |
| 80 |
\& cp1256 cp1257 cp1258 cp37 |
| 81 |
\& cp424 cp437 cp500 cp737 |
| 82 |
\& cp775 cp850 cp852 cp855 |
| 83 |
\& cp856 cp857 cp860 cp861 |
| 84 |
\& cp862 cp863 cp864 cp865 |
| 85 |
\& cp866 cp869 cp874 cp875 |
| 86 |
\& cp932 cp936 cp949 cp950 |
| 87 |
\& dingbats euc\-cn euc\-jp euc\-kr |
| 88 |
\& gb12345\-raw gb2312\-raw gsm0338 hp\-roman8 |
| 89 |
\& hz iso\-2022\-jp iso\-2022\-jp\-1 iso\-8859\-1 |
| 90 |
\& iso\-8859\-10 iso\-8859\-11 iso\-8859\-13 iso\-8859\-14 |
| 91 |
\& iso\-8859\-15 iso\-8859\-16 iso\-8859\-2 iso\-8859\-3 |
| 92 |
\& iso\-8859\-4 iso\-8859\-5 iso\-8859\-6 iso\-8859\-7 |
| 93 |
\& iso\-8859\-8 iso\-8859\-9 iso\-ir\-165 jis0201\-raw |
| 94 |
\& jis0208\-raw jis0212\-raw johab koi8\-f |
| 95 |
\& koi8\-r koi8\-u ksc5601\-raw MacArabic |
| 96 |
\& MacCentralEurRoman MacChineseSimp MacChineseTrad MacCroatian |
| 97 |
\& MacCyrillic MacDingbats MacFarsi MacGreek |
| 98 |
\& MacHebrew MacIcelandic MacJapanese MacKorean |
| 99 |
\& MacRoman MacRomanian MacRumanian MacSami |
| 100 |
\& MacSymbol MacThai MacTurkish MacUkrainian |
| 101 |
\& nextstep posix\-bc shiftjis symbol |
| 102 |
\& UCS\-2BE UCS\-2LE UTF\-16 UTF\-16BE |
| 103 |
\& UTF\-16LE UTF\-32 UTF\-32BE UTF\-32LE |
| 104 |
\& utf8 viscii |
| 105 |
.Ve |
| 106 |
.PP |
| 107 |
(全114種類) |
| 108 |
.PP |
| 109 |
例えば、文字コードFOOのファイルをUTF\-8に変換するには、以下のようにします。 |
| 110 |
.PP |
| 111 |
.Vb 1 |
| 112 |
\& perl \-Mencoding=FOO,STDOUT,utf8 \-pe1 < file.FOO > file.utf8 |
| 113 |
.Ve |
| 114 |
.PP |
| 115 |
また、Perlには、全部がPerlで書かれた文字コード変換ユーティリティ、piconvも付属しているので、以下のようにすることもできます。 |
| 116 |
.PP |
| 117 |
.Vb 2 |
| 118 |
\& piconv \-f FOO \-t utf8 < file.FOO > file.utf8 |
| 119 |
\& piconv \-f utf8 \-t FOO < file.utf8 > file.FOO |
| 120 |
.Ve |
| 121 |
.SS "(jcode.pl|Jcode.pm|JPerl) からの移行" |
| 122 |
.IX Subsection "(jcode.pl|Jcode.pm|JPerl) からの移行" |
| 123 |
5.8以前の、スクリプトがEUC\-JPであればリテラルだけは扱うことができました。また、入出力を扱うモジュールとしてはJcode.pmが( <http://openlab.ring.gr.jp/Jcode/> )、perl4用のユーティリティとしてはjcode.plがそれぞれ存在し、日本語の扱えるCGIでよく利用されていることを御存じの方も少なくないかと思われます。ただし、日本語による正規表現をうまく扱うことは不可能でした。 |
| 124 |
.PP |
| 125 |
5.005以前のPerlには、日本語に特化したローカライズ版、Jperlが存在しました( <http://homepage2.nifty.com/kipp/perl/jperl/index.html> ※1)。また、Mac OS 9.x/Classic用のPerl、MacPerlの日本語版もMacJPerlとして存在してました。( <https://habilis.net/macjperl/> ).これらでは文字コードとしてEUC\-JPに加えShift_JISもそのまま扱うことができ、また日本語による正規表現を扱うことも可能でした。 |
| 126 |
.PP |
| 127 |
Perl5.8では、これらの機能がすべてPerl本体だけで実現できる上に、日本語のみならず上記114の文字コードをすべて、しかも同時に扱うことができます。さらに、CPANなどから新しい文字コード用のモジュールを入手することも簡単にできるようになっています。 |
| 128 |
.PP |
| 129 |
※1: ホスティングサービスの終了により現在は閲覧できません。 Vector( <https://www.vector.co.jp/soft/win95/util/se098198.html> )からWindow用のバイナリを、CPAN( <https://www.cpan.org/src/unsupported/4.036/jperl/> )からperl4用のパッチを入手することができます。 |
| 130 |
.IP \(bu 4 |
| 131 |
入出力 |
| 132 |
.Sp |
| 133 |
以下の例はいずれもShift_JISの入力をEUC\-JPに変換して出力します。 |
| 134 |
.Sp |
| 135 |
.Vb 10 |
| 136 |
\& # jcode.pl |
| 137 |
\& require "jcode.pl"; |
| 138 |
\& while(<>){ |
| 139 |
\& jcode::convert(*_, \*(Aqeuc\*(Aq, \*(Aqsjis\*(Aq); |
| 140 |
\& print; |
| 141 |
\& } |
| 142 |
\& # Jcode.pm |
| 143 |
\& use Jcode; |
| 144 |
\& while(<>){ |
| 145 |
\& print Jcode\->new($_, \*(Aqsjis\*(Aq)\->euc; |
| 146 |
\& } |
| 147 |
\& # Perl 5.8 |
| 148 |
\& use Encode; |
| 149 |
\& while(<>){ |
| 150 |
\& from_to($_, \*(Aqshiftjis\*(Aq, \*(Aqeuc\-jp\*(Aq); |
| 151 |
\& print; |
| 152 |
\& } |
| 153 |
\& # Perl 5.8 \- encoding を利用して |
| 154 |
\& use encoding \*(Aqeuc\-jp\*(Aq, STDIN => \*(Aqshiftjis\*(Aq; |
| 155 |
\& while(<>){ |
| 156 |
\& print; |
| 157 |
\& } |
| 158 |
.Ve |
| 159 |
.IP \(bu 4 |
| 160 |
Jperl 互換スクリプト |
| 161 |
.Sp |
| 162 |
いわゆる"shebang"を変更するだけで、Jperl用のscriptのほとんどは変更なしに利用可能だと思われます。 |
| 163 |
.Sp |
| 164 |
.Vb 3 |
| 165 |
\& #!/path/to/jperl |
| 166 |
\& ↓ |
| 167 |
\& #!/path/to/perl \-Mencoding=euc\-jp |
| 168 |
.Ve |
| 169 |
.Sp |
| 170 |
詳しくは perldoc encoding を参照してください。 |
| 171 |
.SS さらに詳しく |
| 172 |
.IX Subsection "さらに詳しく" |
| 173 |
Perlには膨大な資料が付属しており、Perlの新機能やUnicodeサポート、そしてEncodeモジュールの使用法などが細かく網羅されています(残念ながら、ほとんど英語ではありますが)。以下のコマンドでそれらの一部を閲覧することが可能です。 |
| 174 |
.PP |
| 175 |
.Vb 3 |
| 176 |
\& perldoc perlunicode # PerlのUnicodeサポート全般 |
| 177 |
\& perldoc Encode # Encodeモジュールに関して |
| 178 |
\& perldoc Encode::JP # うち日本語文字コードに関して |
| 179 |
.Ve |
| 180 |
.SS "Perl全般に関する URL" |
| 181 |
.IX Subsection "Perl全般に関する URL" |
| 182 |
.IP <https://www.perl.org/> 4 |
| 183 |
.IX Item "<https://www.perl.org/>" |
| 184 |
Perl ホームページ |
| 185 |
.IP <https://www.perl.com/> 4 |
| 186 |
.IX Item "<https://www.perl.com/>" |
| 187 |
Perl 財団が営業する文章作品集 |
| 188 |
.IP <https://www.cpan.org/> 4 |
| 189 |
.IX Item "<https://www.cpan.org/>" |
| 190 |
CPAN (Comprehensive Perl Archive Network) |
| 191 |
.IP <https://metacpan.org/> 4 |
| 192 |
.IX Item "<https://metacpan.org/>" |
| 193 |
MetaCPAN CPANの検索エンジン |
| 194 |
.IP <https://lists.perl.org/> 4 |
| 195 |
.IX Item "<https://lists.perl.org/>" |
| 196 |
Perl メーリングリスト集 |
| 197 |
.IP <https://perldoc.jp/> 4 |
| 198 |
.IX Item "<https://perldoc.jp/>" |
| 199 |
perldoc.jp Perl の公式ドキュメント、モジュールドキュメントの日本語訳 |
| 200 |
.SS "Perlの修得に役立つ URL" |
| 201 |
.IX Subsection "Perlの修得に役立つ URL" |
| 202 |
.IP <http://www.oreilly.com.cn/> 4 |
| 203 |
.IX Item "<http://www.oreilly.com.cn/>" |
| 204 |
O'Reilly 社のPerl関連書籍(簡体字中国語) |
| 205 |
.IP <https://www.oreilly.co.jp/catalog/> 4 |
| 206 |
.IX Item "<https://www.oreilly.co.jp/catalog/>" |
| 207 |
オライリー社のPerl関連書籍(日本語) |
| 208 |
.SS "Perl に関する団体" |
| 209 |
.IX Subsection "Perl に関する団体" |
| 210 |
.IP <https://www.pm.org/groups/asia.html> 4 |
| 211 |
.IX Item "<https://www.pm.org/groups/asia.html>" |
| 212 |
アジア地域の Perl Mongers (Perlのユーザーグループ) 一覧 |
| 213 |
.IP <https://japan.perlassociation.org> 4 |
| 214 |
.IX Item "<https://japan.perlassociation.org>" |
| 215 |
一般社団法人Japan Perl Association (JPA) Perl技術及び文化の啓蒙・促進のための組織 |
| 216 |
.SS Unicode関連のURL |
| 217 |
.IX Subsection "Unicode関連のURL" |
| 218 |
.IP <https://www.unicode.org/> 4 |
| 219 |
.IX Item "<https://www.unicode.org/>" |
| 220 |
Unicode コンソーシアム (Unicode規格の選定団体) |
| 221 |
.IP <https://www.cl.cam.ac.uk/%7Emgk25/unicode.html> 4 |
| 222 |
.IX Item "<https://www.cl.cam.ac.uk/%7Emgk25/unicode.html>" |
| 223 |
UTF\-8 and Unicode FAQ for Unix/Linux |
| 224 |
.IP <https://wiki.kldp.org/Translations/html/UTF8\-Unicode\-KLDP/UTF8\-Unicode\-KLDP.html> 4 |
| 225 |
.IX Item "<https://wiki.kldp.org/Translations/html/UTF8-Unicode-KLDP/UTF8-Unicode-KLDP.html>" |
| 226 |
UTF\-8 and Unicode FAQ for Unix/Linux (ハングル訳) |
| 227 |
.SH AUTHORS |
| 228 |
.IX Header "AUTHORS" |
| 229 |
.IP \(bu 4 |
| 230 |
Jarkko Hietaniemi <[email protected]> |
| 231 |
.IP \(bu 4 |
| 232 |
Dan Kogai (小飼 弾) <[email protected]> |
| 233 |
.IP \(bu 4 |
| 234 |
Shogo Ichinose (一野瀬 翔吾) <[email protected]> |