Perl -- A tutorial

A few years ago I began to put little snippets of perl code on my website to make it easier for me. This modest tutorial is the result of questions that quickly started coming in.

A word about perl

If you're new to the web, perl (practical extraction and reporting language) is a computer language that many programmers choose to handle cgi (common gateway interface) programming. It is an excellent string parsing language, handles standard Internet communication well, it is easy to use, can be learned quickly, and is free (for the most part).

If you listen to the hype, perl is the greatest thing since buttered toast and if it could cook it would make an excellent wife (or husband). My thoughts on the subject can best be expressed as: There are many programming languages, and each is good for certain tasks and each has weaknesses. I always recommend that a programmer learn more than one language, since it makes them better programmers.

As with any language there are the "gurus" (Larry Wall, Tom Christiansen, and Randal Schwartz actually wrote the book on perl).

Currently, you should be using perl5. Anything earlier is antiquated. Start with an easy program on any new system. The typical "Hello, world" is always the best choice. This will test your shebang (if needed), and a number of other non-perl functions that are necessary to implement perl on your web site.

Getting Started

Okay, let's make a few assumptions. You have a web site and want to make it cool or better or interactive or... None of the readily-available canned programming (see Links) will do the job for you. You are new to perl, and want to pick up enough to do what you need. You probably have done some other programming, maybe in visual basic, or another language, or you at least have a semblance of logical thought.

First, let's briefly describe what is going to happen. You create a script, written in perl. This script is processed by a powerful program called perl.exe. It executes each line in your script. For the purpose of this tutorial we will assume:

  • You are leasing space from one of the many fine hosting companies available.
  • The company allows you access to a cgi-bin directory.
  • The company has perl5 installed and running.
  • You know how to telnet and ftp.

If you are looking for in-depth help on installing perl on a specific platform, please check our links.

Let's write a simple program to test the setup of the system.

print "Content-Type: text/html\n\n";
print "Hello,world";

Cut and paste this file into the editor of choice, save it as text and transport it to your serving via FTP. On many serverrs, file permissions play a role in whether or not the program can be run on the web. To set permissions on a Unix-based system using our FTP client of choice, WS_FTP, simply right-click on the server-side program and left-click on the chmod (UNIX) line. Set the permissions screen to look like this:

To set the permissions using a telnet session, logon, navigate to your cgi-bin directory and enter: chmod 755 (or whatever you called it).

Now let's execute the script. Open your browser and enter the location of the URL to get to the program. It would typically look something like this:

If you can't get this script to run on your website, then you will need to call the tech support people of your hosting company.

Perl tutorial, part II
Return to Perl Help

[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network

In Association with