Chapter 1: Introduction
What's Perl > Task Examples > Running Perl > Variables & Types >
Flow Control > Some Simple Scripts
Examples of Perl tasks
Perl is particularly well suited for gathering and manipulating text. This
is why it is a favorite with system administrators as well as HTML authors.
The following examples only begin to show how perl can be useful to a
Web page serving through CGI
Of course, perl is used extensively in serving up content when run in
concert with a webserver. The webserver knows that certain URL's are meant to
run perl scripts, and when it finds those URL's it runs the perl scripts for
you automatically. The perl program creates output in the form of a webpage
that in turn gets sent to the browser. The user sees a page created on the
fly just for that request.
Talking to web sites and reporting on bits of info
Perl can go and visit a website for you, without you ever using a browser.
It can pull in the whole webpage, and hunt through it for bits of
information. This info can then be repackaged into whatever form you need it:
a different web-page, a printed report, or a piece of email.
The converse of this is that it can submit forms for you and interact with
webservers at the other end. An example of this is an e-commerce transaction
server; perl can send specific information to a payment server and then await
the result to see whether the payment went through properly or not.
Lost cat finder
Okay, we lost our cat last year. The kids were really upset, and we were
all distraught. Then I realized I could get perl to help me find the cat. I
was able to write a perl script that went out over the Internet and collected
and printed the name, address and phone number of all the houses on the
streets in my neighborhood. With that list, we were then able to call every
house one after the other. (We did eventually find the cat.) This is a
concrete instance of the example above - visiting web sites, scraping info
from them and assembling a report.
Web page construction
Perl can be used to construct web pages according to your own defined
rules. As a matter of fact, the navigation links of this website were built
with just such a tool. All the menus down the left hand side on the entire
site are created by a perl script, and they can be updated to a completely
different layout in a matter of minutes.
Web page editing
Perl scripts can make global changes to web pages. With the right script,
presto-chango! wherever a particular phrase is found, it gets replaced
with improved wording. Very broad yet precise changes are possible.
Perl comes with the capability to interact with online "backend"
databases -- the massive storehouses of information running behind the scenes
on large websites. It can search for database records containing particular
pieces of information and it can add new records or update existing records.
With the ability to interact with a user through a web browser, perl can act
as the interface between the user and the database running on the server.
To start getting perl to do the things you want, find out how to run perl
on your computer in the next section.
Email me your comments!