Perl has a culture of useful documentation. The perldoc
utility is part of every complete Perl 5 installationHowever your Unix-like system may require you to install an additional package such as perl-doc
on Debian or Ubuntu GNU/Linux.. perldoc
displays the documentation of every Perl module installed on the system--whether a core module or one installed from the Comprehensive Perl Archive Network (CPAN)--as well as thousands of pages of Perl's copious core documentation.
Use perldoc
to read the documentation for a module or part of the core documentation:
The first example displays the documentation embedded within the List::Util
module. The second example displays a pure documentation file, in this case the table of contents of the core documentation. The third example displays a pure documentation file included as part of a CPAN distribution (moose). perldoc
hides these details; there's no distinction between reading the documentation for a core library such as Data::Dumper
or one installed from the CPAN.
The standard documentation template includes a description of the module, demonstrates sample uses, and then contains a detailed explanation of the module and its interface. While the amount of documentation varies by author, the form of the documentation is remarkably consistent.
The perldoc
utility has many more abilities (see perldoc perldoc
). The -q
option searches only the Perl FAQ for any provided keywords. Thus perldoc -q sort
returns three questions: How do I sort an array by (anything)?, How do I sort a hash (optionally by value instead of key)?, and How can I always keep my hash sorted?.
The -f
option displays the documentation for a builtin Perl function. perldoc -f sort
explains the behavior of the sort
operator. If you don't know the name of the function you want, browse the list of available builtins in perldoc perlfunc
.
The -v
option looks up a builtin variable. For example, perldoc -v $PID
displays the documentation for the variable which contains the current program's process id. Depending on your shell, you may have to quote the variable appropriately.
The -l
option causes perldoc
to display the path to the documentation file rather than the contents of the documentationBe aware that a module may have a separate .pod file in addition to its .pm file..
The -m
option displays the entire contents of the module, code and all, without performing any special formatting.
Perl 5's documentation system is POD, or Plain Old Documentation. perldoc perlpod
describes how POD works. Other POD tools include podchecker
, which validates the form of your POD, and Pod::Webserver
, which displays local POD as HTML through a minimal web server.
Hey! The above document had some coding errors, which are explained below:
- Around line 3:
-
A non-empty Z<>
- Around line 7:
-
Deleting unknown formatting code N<>
- Around line 85:
-
Deleting unknown formatting code N<>