![](https://csdnimg.cn/release/download_crawler_static/9920159/bg10.jpg)
Modern Perl
Perl has lots of documentation. Where do you start?
perldoc perltoc displays the table of contents of the core documentation, and perldoc perlfaq is the ta-
ble of contents for Frequently Asked Questions about Perl. perldoc perlop and perldoc perlsyn document
Perl's symbolic operators and syntactic constructs. perldoc perldiag explains the meanings of Perl's warning
messages. perldoc perlvar lists all of Perl's symbolic variables.
You don't have to memorize anything in these docs. Skim them for a great overview of the language and come back
to them when you have questions.
How to Read the Documentation
The perldoc utility can do much, much more (see perldoc perldoc). Use the -q option with a keyword to search the Perl
FAQ. For example, 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 shows the documentation for a builtin Perl function, such as perldoc -f sort. 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 explains $PID, which is the variable containing the
current program's process id. Depending on your shell, you may have to quote the variable appropriately.
The -l option shows the path to the file containing the documentation. (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 any special formatting.
Perl uses a documentation format called POD, short for Plain Old Documentation. perldoc perlpod describes how POD
works. Other POD tools include podchecker, which validates the structure of POD documents, and the Pod::Webserver
CPAN module, which displays local POD as HTML through a minimal web server.
Expressivity
Before Larry Wall created Perl, he studied linguistics. Unlike other programming languages designed around a mathematical
notion, Perl's design emulates how people communicate with people. This gives you the freedom to write programs depending
on your current needs. You may write simple, straightforward code or combine many small pieces into larger programs. You
may select from multiple design paradigms, and you may eschew or embrace advanced features.
Learning Perl is like learning any spoken language. You'll learn a few words, then string together sentences, and then enjoy
simple conversations. Mastery comes from practice of both reading and writing code. You don't have to understand every detail
of Perl to be productive, but the principles in this chapter are essential to your growth as a programmer.
Other languages may claim that there should be only one best way to solve any problem. Perl allows you to decide what's most
readable, most useful, most appealing, or most fun.
Perl hackers call this TIMTOWTDI, pronounced “Tim Toady”, or “There's more than one way to do it!”
This expressivity allows master craftworkers to create amazing programs but also allows the unwary to make messes. You'll
develop your own sense of good taste with experience. Express yourself, but be mindful of readability and maintainability,
especially for those who come after you.
Perl novices often find certain syntactic constructs opaque. These idioms (Idioms, pp. 158) offer great (if subtle) power to
experienced programmers, but it's okay to avoid them until you're comfortable with them.
As another design goal, Perl tries to avoid surprising experienced (Perl) programmers. For example, adding two variables
($first_num + $second_num) is obviously a numeric operation (Numeric Operators, pp. 64). You've expressed your intent
to treat the values of those variables as numbers by using a numeric operator. Perl happily does so. No matter the contents of
$first_num and $second_num, Perl will coerce them to numeric values (Numeric Coercion, pp. 50).
Perl adepts often call this principle DWIM, or do what I mean. You could just as well call this the principle of least astonishment.
Given a cursory understanding of Perl (especially context; Context, pp. 3), it should be possible to understand the intent of an
unfamiliar Perl expression. You will develop this skill as you learn Perl.
2