[Perl.sig] Plain Old Documentation
Litss Coordinator
litss.coord at anu.edu.au
Tue Mar 22 12:24:52 EST 2005
==== Announcement ====
Due to popular demand we have now scheduled a run of our very popular
``Welcome to Perl'' courses in Canberra. These will be running in early
May. The early bird date for these courses is the 1st of April, so get
your booking in as soon as possible!
==== Data::Dumper ====
In the previous Perl tip we mentioned that there is no way to use
``Data::Dumper'' to print the code from a subroutine reference, Bryon
Ellacott was kind enough to inform us that this is no longer the case
with modern versions of Perl.
If you are using ``Data::Dumper'' version 2.121 you can access the code
within a subroutine reference by setting the ``Data::Dumper::Deparse''
variable to a true value.
use Data::Dumper;
$Data::Dumper::Deparse = 1;
# Here's a preference to a subroutine...
my $subref = sub {
my ($x, $y) = @_;
# Return the larger of two arguments.
if ($x > $y) {
return $x;
}
return $y;
};
# Since $Data::Dumper::Deparse was set to true, this correctly
# prints the subroutine's code.
print Dumper $subref;
This will only work if your subroutines can be properly reconstructed
using ``B::Deparse''.
==== Perldoc ====
While opinions vary about the elegance and beauty of Perl, many people
agree that Perl is one of the most well documented programming language
in use today. Better still, much of that documentation is freely
available and comes standard with Perl.
Most of Perl's documentation is accessible through the perldoc utility.
Perldoc reads POD (plain old documentation) out of .pod files or from
within the source of modules and programs themselves. This Perl tip is
going to discuss some of the documents and perldoc switches that we
find
invaluable.
To learn more about how to write your own POD documentation read
``perldoc perlpod''.
== Module documentation ==
Individual module documentation
To read the documentation from any installed module we can write:
perldoc <module_name>
for example:
perldoc CGI
For multi-part module names, such as ``Scalar::Util'', we can type
either of the following:
perldoc Scalar::Util;
perldoc Scalar/Util;
although the first form is more regularly seen.
Module source
Sometimes we want to browse the source of a module without having
to
find out where the module is installed. To do this, we can use the
*-m* switch to Perldoc:
perldoc -m CGI
Be aware that under older versions of perldoc this will display the
source of the file containing the POD. For modules that separate
code and pod, ``perldoc -m'' may not do what you expect.
Standard installed modules
To find out which modules were installed with Perl by default read:
perldoc perlmodlib
Non-standard installed modules
To see a list of the modules you've installed since Perl was
installed read: perldoc perllocal
Note that this page may not always be accurate. Modules installed
into user directories are not typically added to the perllocal
list.
Further, the ``perllocal'' list may not writable by the user at the
time of module installation. Finally, modules installed using your
operating system's packaging system (eg, RedHat RPM files, or
Debian
.deb files) rarely appear in ``perllocal''.
== Function documentation ==
Perhaps the most used switch to Perldoc is *-f*. This provides a full
description of any Perl function. Thus, to find out all we could ever
want to know about print, we'd type:
perldoc -f print
These pages provide information about what arguments our functions
take,
what they return, example uses, caveats and more.
To find the documentation for the file test operations type:
perldoc -f -x
The *-f* switch pulls its data from the ``perlfunc'' page. Thus if you
wish to browse Perl's functions you may wish to start there.
== Questions and answers ==
Perl has a number of FAQ files. These range from general questions
through to quite specific topics.
Frequently asked questions
To find out all the topics covered in the FAQs you can read:
perldoc perlfaq
Searching the FAQs
Perl has a great focus on laziness. As a result you can search the
FAQs with a regular expression, from the command line. To do this,
provide a regular expression (or a string of interest) to perldoc
with the *-q* flag:
perldoc -q 'CGI script'
perldoc -q 'CGI script.*browser'
This then searches the headings (questions) of the entries in the
FAQs for your matches. You can also pass in keywords which interest
you:
perldoc -q CGI script
which returns more results than the previous search.
== General pages ==
Well beyond the few uses above, Perl has a great many more pages.
To
find a list of all of these read:
perldoc perl
or (to find these broken into more meaningful sections):
perldoc perltoc
= Tutorials =
In particular, the tutorials are well written and a great place to
start to learn about new topics. Popular tutorials include:
perldoc perlreftut (References)
perldoc perlopentut (Open)
perldoc perldebtut (Debugging)
perldoc perlretut (Regular expressions)
perldoc perlboot (OO for beginners)
perldoc perltoot (OO part 1)
perldoc perltootc (OO part 2)
perldoc perlthrtut (Threads)
perldoc perlxstut (XS)
==== Upcoming Courses in Canberra ====
http://perltraining.com.au/bookings/Canberra.html
Introduction to Perl 3rd May - 4th May
Intermediate Perl 5th May - 6th May
==== Upcoming Courses in Melbourne ====
http://perltraining.com.au/bookings/Melbourne.html
Database Programming with Perl 12th May
Perl Security 13th May
==== Upcoming Courses in Sydney ====
http://perltraining.com.au/bookings/Sydney.html
Database Programming with Perl 26th May
Perl Security 27th May
==== Corporate Courses ====
http://perltraining.com.au/corporate.html
Do you have a large group, or the need for training at a particular
time? Perl Training Australia is happy to arrange a course in the
time and place that best suits you. For more information read our
page on Corporate Courses at
http://perltraining.com.au/corporate.html or call us on
+61-3-9354-6001.
_______________________________________________
This Perl tooltip and associated text is Copyright Perl Training Australia.
You may freely distribute this text so long as it is distributed in full
with this Copyright noticed attached.
If you have any questions please don't hesitate to contact us:
Email: contact at perltraining.com.au
Phone: 03 9354 6001
Perl-tips mailing list
To change your subscription details visit:
More information about the Perl.sig
mailing list