meeting the graphic and web design needs of small businesses

SiteMaster Internet Services

Perl and CGI resources - FAQs

What is Perl

Perl is a programming language that many people have used to make their web pages interactive.

It was designed by Larry Wall in 1986 to help him create reports, and since then it has been developed and changed.

What is a Perl script

Programs written in Perl are referred to as scripts.

What is CGI

Common Gateway Interface - the standard for communication between web pages and other programs running on a web server. It's what allows the programs to communicate with each other and so make things happen when you enter data into forms on web pages. Without it all pages would be static, which means they could not respond to you in any way.

Why is Perl used for CGI and the Internet : Where do I buy scripts

Text manipulation! Perl can examine and manipulate text like no other programming language. I've been writing code for many years, but I have never seen anything like the power and ease with which Perl searches and manipulates text, arrays etc.

Portability - you can generally take a script off one computer and put it onto another and it will work without modification. That's a really essential feature especially on the Internet where there are so many different machines in use.

Cost - Perl can be downloaded FREE. So you don't have to be rich to get going, however, a couple of good books will help you get to grips with it. The downloadable distribution comes with full documentation, but it's not the easiest to follow if you are new, or even if you are already familiar with another programming language.

Finally, it's a good language to work with, easy to do things in lots of different ways, once you get started you begin to appreciate the possibilities and your appetite is insatiable.

Are there any drawbacks to using Perl

Well . . . . the error detection in the interpreter is not as good as in many compilers, so you can sometimes be puzzled by what and where the error is.

When you run scripts on a server, you will often get a single error message when your script does not work. This is very frustrating because you have no idea where to look for the error.

A strategy for tackling this is to ensure you start with a working script even if it does not have all the facilities you need. Then modify it in small stages so that when you have difficulties you know exactly where to look for the problem. As you make changes, save your new version in a file with a different name, so you can revert back to the previous one without difficulty.

What do scripts do

The easy answer is they do what the designer and programmer wanted, but in more useful terms they take data which the viewer of a page enters and process that data when it is send to a web server.

Take a simple example where you put you e-mail address into a box to join a mailing list.

How Perl scripts can be used to interact with website users

When you click the 'Join' button on the web page, your browser sends the contents of the box to the server, which passes it to the appropriate script for processing. Usually the script would check the e-mail address to see that it contains the expected form of email address, sends a visual confirmation page back to the browser, adds the email address to the mailing list and probably sends a 'welcome' email too.

All this can be achieved very easily with Perl.

Can I run Perl scripts in my webspace

When you run a script on a server you have a lot of control over that computer, so most hosting companies give you very restricted access to scripts. Hardly surprising really, because badly written or malicious scripts are a security hazard.

If you are with one of the 'free' services such as Freeserve, Connectfree, Btinternet, Tesco etc etc, you will probably have access to just two scripts, a counter and a form processor, The counter just lets you put a simple count on your pages, and the form processor lets you have simple forms which visitors can complete, and the results will be sent to you. These providers are giving you free space and e-mail, but they are very restricted when it comes to real programs running on their servers.

To run scripts you need your own CGI-bin, that's a directory within your server space where you keep all your scripts, and from where they are run. The server has to be set up so that when your scripts are running they are kept within strict control, so that if they run amuck throwing brickbats then no other user on the server can be affected. If you want to run a forum or have real interaction with your visitors, then you will not be able to do it with free webspace - after all the companies providing it have to keep their servers secure. They are not in business to provide freebies they are in business to make money for their shareholders.

Where do I find scripts on the Internet

A couple of starting points are:

world wide mart | CGI-resources

Searching for "CGI scripts" or "free CGI scripts" is the quickest way, note that putting the search phrase in double quotes normally tells the search engine to search for the exact phrase, so you will find just what you're looking for.

Can I write my own scripts

It's not that difficult, but before you start coding check first that your webspace allows you to run scripts which you have written yourself, and that the script you want is not available to purchase or download for free. Why spend hours learning a programming language and writing a script yourself if someone else has already done the hard work. In general the price asked for scripts is just a fraction of the cost which will be entailed in writing them, as the author expects to sell them many times over.

Where do I find Perl resources like tutorials

One easy way is to search with a string such as "Perl tutorial", which will come up with a good response.

What good books are there on Perl

I bought the following two books after an extensive search in my local bookshop, and have found them really useful - I'll explain why.

It contains 24 one-hour lessons in Perl programming, plus a CD which has all the software for Mac, Wintel machines and Unix. Including all the examples, the Perl interpreter etc. This saves downloading.

The pace of the book is steady, the lessons are self-contained, and take you through the language in a logical and methodical way. There are also sections on how Perl scripts and web pages interact, which are very useful. This book will get you through the basics and writing Perl. Expect to spend an hour on each of the lessons.

This is a 'Visual Quickstart Guide'. The layout of the pages is graphic, with lots of illustrations (screenshots) showing exactly how to do things. The book plunges you in FAST. The explanations are clear and concise, no wasted words, but it's all there. The parts about using Perl with web pages are very good and really get you working quickly.

I bought both books and I'm really glad I did, I found the quickstart excellent for grabbing the concepts, and the 24 hour lessons good where I wanted more explanation, and to be taken through a concept in more detail. I often found myself with both books open, cross checking between them.

There are other books on Perl and related programming

 

PHP is another type programming that can be used to make web pages interactive, it can be easier to program than Perl and is embedded into web pages. The PHP coding is interpreted on the server BEFORE the page is served to the user.