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』

第11章 Perlモジュール Perlモジュール

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

解決すべき問題があれば、おそらく誰かがすでにそれを解決し、その解決策をComprehensive Perl Archive Network (CPAN)で公開している。CPANは、再利用可能なPerlコードの何千ものモジュールを含む、世界規模のサーバとミラーのコレクションである。ラリーがPerlを拡張可能な言語として設計したためだ。

ここではモジュールの書き方を教えるつもりはない。この章では、すでに存在するモジュールの使い方を紹介する。この章では、モジュールに関する調査をするのではなく、CPANを使い始めることを目的としている。

モジュール発見

モジュールには2種類ある:Perlに付属していて、すでに入手可能なものと、CPANから入手して自分でインストールするものだ。特に断らない限り、ここで紹介するモジュールはPerlに付属している。

注

ベンダによっては、純正バージョンのPerlでさらに多くのモジュールを提供している。ベンダモジュールという第3のタイプもあるが、それはおまけのようなものだ。あなたのオペレーティングシステムをチェックして、他にどんなモジュールがあるか調べてみよう。

Perlに付属していないモジュールを発見するには、MetaCPANから始めよう。モジュールをわざわざインストールしなくても、ディストリビューションをブラウズしてファイルを覗くこともできる。パッケージ全体をダウンロードする前に、モジュールのドキュメントを読むことができる。ディストリビューションを調べるためのツールは他にもたくさんある。

しかし、モジュールを探しに行く前に、すでにインストールされているかどうかをチェックすべきだ。一つの方法は、perldocでドキュメントを読んでみることだ。 Digest::SHA モジュールはPerlに付属している(そして後で使う)ので、そのドキュメントを読むことができるはずだ:

$ perldoc Digest::SHA

存在しないモジュールで試すとエラーメッセージが出る:

$ perldoc Llamas
No documentation found for "Llamas".

ドキュメントは、あなたのシステムでも他の形式(HTMLなど)で利用できるかもしれない。ドキュメントがあれば、モジュールはインストールされている。

Perlに付属しているcpan コマンドを使えば、モジュールの詳細を知ることができる:

$ cpan -D Digest::SHA

モジュールをインストールする

まだ持っていないモジュールをインストールしたいとき、ディストリビューションをダウンロードして解凍し、Shellから一連のコマンドを実行するだけでいいことがある。Perlディストリビューションには2つの主要なビルドシステムがあり、同じように使用する。READMEファイルやINSTALLファイルに詳細が記載されているか確認してほしい。

モジュールがPerl付属のExtUtils::MakeMaker を使っている場合、シーケンスは次のようになる:

$ perl Makefile.PL
$ make install

システム全体のディレクトリにモジュールをインストールできない場合は、Makefile.PLへの引数(INSTALL_BASE )で別のディレクトリを指定することができる:

$ perl Makefile.PL INSTALL_BASE=/Users/fred/lib ...
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