What are some practical applications for Perl?

Victor Odhner plug-discuss@lists.plug.phoenix.az.us
Tue, 21 May 2002 14:32:12 -0700


Mark Berkwitt wrote:
> I'm considering learning Perl but I don't know what
> Perl will give me.

Perl has proven a great language for CGIs, that is,
external programs called by a web server to service
web requests.  That's the good news.  The bad news is
that in-process services such as PHP are more efficient
and will be replacing Perl over coming years.

Perl is absolutely a killer language to do text
processing of any type.  If you are doing data
conversions, scanning for complex patterns, or
otherwise manipulating characters, Perl is great.

Perl is somewhat like an interpreted C language,
so it has access to most of the library functions
available in C, plus better string handling.
It can do sockets, spawn sub processes, etc.
So if you need to write a one-off program, Perl
is far more economical than C in terms of the
development time.  For a long term application,
Perl may be just as efficient as C if the task
is not very CPU intensive.  It is used heavily
by system administrators.  It has total reach into
the Unix API, so it is a fantastic workhorse.

If you want to read through an input file, accumulate
and classify things from the input data, and then spit
the results out as a summary or in a different order,
Perl will do this far faster than C can, because of its
regular expressions and associative arrays (hashes).

Perl is a big and somewhat ungainly language, and you
will probably end up only using a small subset.
For this reason, it may not be a good idea to try
to "learn Perl".  Just USE it, and learn what works
for you.  Especially, any time you have a shell script
that is beginning to get a tad complicated, think
about switching into Perl for that job.  A lot of it
will be easy to port from shell.  (But if you are
"dotting in" or "sourcing" a configuration file in
your shell script, leave that part of the job as a
little shell script paired with the Perl program.)

Perl has (at cpan.org) an impressive set of solutions
in the form of library modules, so some of your
use of Perl might turn out to be just tying these
things together.  But some of these library modules
kill the mosquito with a shotgun, so you might want
often to just hack out your own solution.

When writing Perl, write it pretty.  As with any other
language, your little hack may easily grow to be a
serious program, and you need to write it to be
maintainable.

BTW:  I'm NOT a Perl scripter.  I'm a Perl programmer.
Your mileage may vary.

Get a good understanding of hashes and regular
expressions.  This positions you do solve
just about any problem.

Given any problem, I'll be happy to sketch a
solution for you.

Vic