Resources for SPPSR Web Content Providers:
Perl Advice

by Danny Krouk

This area is designed to provide general advice on how to conceptualize and go about a Perl programming project. This area is not designed to teach you how to program in Perl.


Contents of Page One

What is Perl? Planning a Perl Project

What is Perl?

Perl is a programming language. HTML is a language that lets you control how a document appears in WWW Browsers; it is essentially a formating language. Perl is a language that allows you to control the computer, in this case the server.

You can use Perl to build Common Gateway Interfaces (CGI) between the web and computer processes. In other words, you can use Perl to take variables from web-pages (through forms, for instance), tell the computer to do things (like store, sort, process, retrieve information), and return output to the web. This is the "interface".

You should keep in mind that while HTML is easy, Perl is not. It is a very learnable language. However, successful programming is not as swift or as straight-forward a process as producing web-pages. All of this being said, Perl programming for inter-activity is very doable and can be used to create very valuable components to your sites. I encourage you to work with it.

Planning a Perl Project

Planning out a process for tackling your programming project is key. Programming can be very frustrating. Following a clear and methodical process can help reduce the frustration that you will experience. Here is (more or less) how I go about planning a Perl project:
  1. Get a clear sense of what you want your Perl program (or "script") to accomplish. I would suggest sketching a diagram of inputs, processes (with all contingencies mapped), and outputs.
  2. Check to see if your plan is doable. I usually look at a Perl book, Perl web-pages, or talk to a Perl person to get a sense of how complicated my project is. I might think its easy, but people familiar with Perl or programming, might point out things that will make it hard.
  3. Next, see if anyone else has already done it, or done something like it. A lot of Perl programmers post their Perl scripts (with annotations) to internet sites. Many of these scripts are free. The University of Florida maintains a library of free scripts. Your HTML and CGI Unleashed book (or any Perl-related book) is also a good source of free scripts or partial scripts. Lastly, there's a nice tutorial with lots of free Perl scripts that I like quite a bit. You need to be mindful that some of the information is UNIX-specific, though.
  4. After I gather my Perl snippets, I try to put them together in my Perl diagram. This helps me figure out if I really have enough pieces to solve all of the issues that I've go to handle. It also helps me designate common and logical variable names, etc.
  5. The final step in this process is to sit down and begin coding the program. I find that it is very helpful to work incrementally. In other words, I write a couple lines of code and try to make them work. Then, I write another couple lines of code and try to make them work. This can be slow. However, it helps avoid the nightmare of having written a whole program and having no idea why it won't run.
  6. Along these lines, it is useful to try running parts of your program "on the command line", rather than through the WWW. Error diagnosis is very difficult if you are not sitting in front the computer that just ran your program.

Page Two provides some information on the structure of Perl. What are the types of variables? What are the control structures? How do you work with files? etc. This is not designed to provide you enough information to program in Perl. You need to buy a book.

Urban Planning School of Public Policy & Social Research UCLA