Who's Afraid of Perl?
April 26, 1999
Many Perl practitioners are zealots for the cause -- Perl
has evolved into a near-religion for many programmers.
The great advantage of this is that there are many folks
out there who sincerely believe in the language and work hard
on its behalf in continued support and development. The
disadvantage of this zealotry is a somewhat Hare Krishna-esque
style of evangelism which may intimidate many newcomers.
Perl "mongers", as they like to be known, find great
pleasure in maximizing their use of this tool, which often
comes out in the form of incredibly cryptic Perl programs
which pack extreme amounts of processing into small amounts
of code.
A typical Perl monger, for example, will while away the
better portion of a weekend in a darkened room and proudly
produce the following gem:
$*=q^00$2b{29}2a;30$17>24&25*2a(1e)1b;
28+1d-26/1b=28+22*1c(1e)17;19@21^, $*.="[1b]28";
$z="";@%=split/\W/,$*;@_=map{hex}@%;
for(@_){$_=chr($_+74);s%[zgf]%$z%g;my$t=$_;push@#,sub{$t};}
for(@#){print&$_}0xf00f&print$/;
Scary stuff! What does it do? I have no idea! However,
this is the kind of Perl that Perl mongers love to show
off as to why Perl is so great. Unfortunately, well-meaning
though they may be, Perl mongers often lack the ability to
empathize with normal humans, to whom the above code
provides every reason to find a different line of work.
Such as botany.
Beginner's can take solace -- Perl programs need not be
cryptic at all; in fact, they can be quite logical
and easy to understand. Although such a style may not leverage
the full power of Perl, it does wonders to improve the
relationship between Perl and human, and this tutorial
will definitely favor legible, clear code over the Perl
monger style.
Why Perl and CGI
Web developers most frequently use Perl in the context
of CGI. CGI has been overdescribed to the point of vagary
and mystery for many new developers, but the concept is
quite simple: the user provides some information on the web page
and the browser sends this information to the web server. The
web server passes this information to a particular program,
this program "does a bunch of stuff" with the
information, returns some results to the web server, which
passes the results back to the user's browser.
CGI, which translates to "Common Gateway Interface",
simply defines the means by which the user's data passes from
the web server to the processing program and back. That's
basically all you need to know about the internal guts of CGI.
The key idea to take away from this is that the program which
"does a bunch of stuff" with the user's data can
be written in any computer language which runs on the server
and can communicate with the server via CGI.
Enter Perl -- Perl can "speak" CGI fluently and
happens to be well-suited to manipulating data, which is
exactly why Perl is the most common language used in developing
CGI interactions.
CGI and Perl are such a powerful combination because,
leveraged on the flexibility of Perl, almost any conceivable
type of processing can constitute the "does a bunch of
stuff" portion of the CGI interaction. Thus, when the
Perl program receives the user's data it could follow any
number of paths, from retrieving information from a database
to constructing and delivering whole new web pages on-the-fly
(known as "dynamic content").
But let's not overwhelm. First we'll look at using Perl
to build some simple programs and then we'll see how to
tie these programs into CGI interactions over the Web.
The Perl You Need to Know
The Perl You Need to Know
Getting Perl
|