Skip to Content
『Learning Perl, 8th Edition』
book

『Learning Perl, 8th Edition』

by Randal L. Schwartz, brian d foy, Tom Phoenix
March 2025
Beginner to intermediate
398 pages
5h 33m
Japanese
O'Reilly Media, Inc.
Content preview from 『Learning Perl, 8th Edition』

付録 C. ユニコード入門

これはUnicodeの完全な、あるいは包括的な入門書ではない。本書で紹介するUnicodeの部分を理解するのに十分なものだ。Unicodeが厄介なのは、文字列について考える新しい方法であり、調整された語彙がたくさんあるからだけでなく、一般にコンピュータ言語がUnicodeをあまりにお粗末に実装してきたからでもある。Perlはv5.6以降、バージョンアップを重ねるごとにUnicodeへの完全準拠に近づいている。 PerlのUnicodeサポートは、間違いなく最も優れている。

ユニコード

ユニバーサル文字セット(UCS)は、文字と コード点との抽象化マッピングである。メモリ上の特定の表現とは何の関係もない。つまり、どのプラットフォームにいても、文字について話す少なくとも一つの方法について合意することができる。エンコーディングは、抽象化されたマッピングをコンピュータ内で物理的に表現することで、コード点をメモリ上の特定の表現に変える。Unicodeについて話すときは、オクテットという用語を使うが(図C-1参照)、おそらくこのストレージをバイト単位で考えていることだろう。エンコーディングによって、文字の格納方法は異なる。逆にオクテットを文字としてインタプリタするには、それをデコードする。Perlがそのほとんどを処理してくれるからだ。

コードポイントについて話すときは、16進表記の数を次のように指定する:(U+0158)。これは文字Řである。コードポイントには名前もあり、そのコードポイントは "LATIN CAPITAL LETTER R WITH CARON "である。それだけでなく、コードポイントは自分自身についてあることを知っている。大文字と小文字、文字か数字か空白文字かなどだ。大文字か小文字か、文字か数字か、空白文字かなども知っている。つまり、特定の文字を扱うことができるだけでなく、文字の種類について話す方法ができたということだ。Perlのライブラリ・ディレクトリの中にunicoreディレクトリがないか探してみよう。そうすることで、Perlは文字について知っておくべきことをすべて知ることができる。

図 C-1. 文字のコード点はその記憶域ではない。エンコーディングは文字をストレージに変換する。

UTF-8と仲間たち

Perlで好まれるエンコーディングはUTF-8で、UCS Transformation Format 8-bitの略である。Rob PikeとKen Thompsonがある晩、ニュージャージー州の食堂でランチョンマットの裏に定義したエンコーディングだ。他のエンコーディングのような欠点がないため、非常に人気のあるエンコーディングではあるが、可能性のあるエンコーディングのひとつに過ぎない。Windowsを使っているなら、UTF-16に遭遇する可能性が高い。このエンコーディングについていいことは何もないので、母親に言われたように黙っておこう。

全員の同意を得る

Unicodeを使用するようにすべてをセットアップするのはイライラするものだ。なぜなら、システムのあらゆる部分が、どのエンコーディングが正しく表示されるかを知る必要があるからだ。どの部分を間違えても、どの部分が正しく動作していないのか見当がつかず、ちんぷんかんぷんな文字が表示されるかもしれない。プログラミングがUTF-8を出力する場合、ターミナルはそれを知っている必要がある。UTF-8を入力する場合、Perlプログラムはそれを知っている必要があるので、入力文字列を正しくインタプリタする。データベースにデータを入れる場合、データベース・サーバはそれを正しくストアし、正しく返す必要がある。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning Perl, 8th Edition

Learning Perl, 8th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
The AWK Programming Language, 2nd Edition

The AWK Programming Language, 2nd Edition

Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger

Publisher Resources

ISBN: 9798341636231