17 Part 16: The End

LinuxChix Perl Course Part 16: The End

1) Parting Words
2) RTFM
3) Use Strict and Warnings
4) Maintainability
5) Platform Independent Shell Scripts
6) TIMTOWDTI
7) Don't Use Perl for Everything
8) Answers to Previous Exercises
9) Acknowledgements
10) Licensing


----------------------------------------

1) Parting Words

Congratulations: you have finished the Perl course. You are now ready
to write your own small Perl scripts or, better yet, dig into someone
else's Perl code to learn more.

In this "epilog" I give my final words of advice.

----------------------------------------

2) RTFM

Perl truly has almost endless tools and tricks, and even the most
seemingly banal parts of the language have surprises. Browse through
the avalanche of documentation a little at a time. The complete list
is here:

[you@localhost]$ man perl

As Larry Wall said in an interview
<http://www.linuxjournal.com/article/3394>, "I've certainly tried to
put a universe of ideas into Perl, with some amount of success."

Don't reinvent the wheel! RTFM, and then search CPAN.

----------------------------------------

3) Use Strict and Warnings

I said this at the beginning of the course, and I'm repeating it now:
begin all of your Perl programs like this:

#!/usr/bin/perl -w
use strict;

Those two lines will save you hours of debugging.

----------------------------------------

4) Maintainability

The standard rules on making maintainable code apply all the more to
Perl, because Perl doesn't force you to write readable code. In
particular, think about how you'll scratch your head a year from now
wondering what that big regular expression means. You'd better put in
lots of comments!

----------------------------------------

5) Platform Independent Shell Scripts

Consider using Perl as a platform independent shell scripting
language. Most shell scripts depend on a host of other programs (like
"grep" and "sed") whose exact implementations vary from one machine
to another - not to mention the fact that they're not available on
Windows. Perl is platform independent, with certain obvious
exceptions such as the "chmod" function.

Perl even allows you to think in shell script mode, as this mini Perl
script demonstrates:

if ( -d $dir ) {
chdir $dir;
}
unlink "some_unwanted_file";

----------------------------------------

6) TIMTOWDTI

Perl hackers insist that There Is More Than One Way To Do It
(TIMTOWDTI, pronounced Tim-Towdty). Look at all the possibilities.

But also remember to use the best tool for every job. For example,
don't do heavy XML processing with m// and s///. Instead, use Perl's
own XML libraries, which are introduced at
http://www.xml.com/pub/a/2000/04/05/feature/

----------------------------------------

7) Don't Use Perl for Everything

Finally, extend TIMTOWDTI by considering possibilities beyond Perl.
Perl is the best tool for a lot of things, but it's not the best tool
for everything. If you don't need Perl's text processing power, then
consider other languages like Python and Ruby. If you're mostly
manipulating XML, consider using XSLT with a small Perl front-end.

----------------------------------------

8) Answers to Previous Exercises

a) The "ref" function, when called on an object, returns the object's
class.

In Perl a class is identified by the package (namespace) in which the
it is defined. Every module must also have its own package, so a
class is package and a module is a package. To find out more about
packages:

perldoc -f package

b) The "English" module provides more intuitive names for weird Perl
variables like "$(" (group ID) or "$|" (automatic output flushing).
For more information on the "English" module:

perldoc English

For more information on those funny Perl variables:

perldoc perlvar

----------------------------------------

9) Acknowledgements

A big thank you to Jacinta Richardson for suggestions and
proofreading. More advanced Perl users might want to check out the
free material from Perl Training Australia
<http://www.perltraining.com.au/>, which she is a part of.

Other contributors include Meryll Larkin.

----------------------------------------

10) Licensing

This course (i.e., all parts of it) is copyright 2003-2005 by Dan
Richter and Alice Wood, and is released under the same license as
Perl itself (Artistic License or GPL, your choice). This is the
license of choice to make it easy for other people to integrate your
Perl code/documentation into their own projects. It is not generally
used in projects unrelated to Perl.