web design and hosting

Perl Programming

Perl is a developers programme - unlike html in which most web pages are written, and like all "proper" programme languages, is unforgiving in so far as - get it wrong, and you get nothing but an error message, so it is not for the faint hearted.

So, why use it ? It's chief use is to make the pages dynamic, which means that the pages can respond to the users input, and can do a variety of things such as generate page counters, send email, do simple and complex calculations, provide statistics, carry out searches, and in it's more complex form can undertake shopping cart programmes, as well as a host of other functions, which html can't do unaided.

It's use is best demonstrated by a few examples:-



Here below is the output of a simple counter, which is counting the hits on this page. It requires no special page format (such as SSI - for those who understand that - these pages are not SSI pages), but a simple HTML call to an image file, which html is fooled into thinking that we are fetching an image, while all the time, it is in fact calling a perl script. You will notice that I have pre-set the counter to give 4 places, and that is why there will be some preceding zeros for some time to come. To test the counter, just hit the 'Refresh' button at the head of your browser, and the count will increment by one:

Full size images from thumb nails

The hard way of creating click through from thumbnail images to full sized images is to create a separate page for each image. The easy way is to create one scripted page that will accept all the references sent to it, and organise the page and image size according to the data sent from the thumbnail. An exaple can be seen on the Sugar Surgeons page where a selection of wedding cakes can be viewed. While the full sized images are different sizes, the script accepts the data from the thumbnail, and adjusts accordingly. To see this in action press [ HERE ]

Email Enquiry Forms

One of the classic uses of script is for the generation of Form Pages, nothing new here, but in this example we have gone slightly upmarket in so far as you may test this script for yourself, put in your own email address, and it will send not only an email to the client to whom it is addressed, but will also send an acknowledgement back to the sender.

We can validate any or all of the Input Boxes, and in this case we have just validated the email entry box, so that if you enter an email adress that does not follow the normal pattern, or forget to enter anything, you will get an error message. Try this for yourself, and if you have entered your email address correctly, you will find your acknowledgement as soon as you collect your email next time. Press [ HERE ]


These beasties are quite harmless in the main and we can use them to good effect to save our clients time as well as add a bit of magic to a page. In the email example above, if you send the form to your own correct details, and then access the form a second time over, you will find that it has inserted your details, all as you entered them except for the information in the text box at the bottom. Return to the link above, and try it for yourself, there is no need to send the form a second time - just hit the 'Last Page' button, and it will close the page.

There is one proviso, and that is that your browser needs to be cookie enabled, else it won't work.


To demonstrate perl's ability to do complex as well as simple calculations as a response to user input, I have created a compound interest programme that enables you to determine the value of an investment or deposit over a given term of years. Press [ HERE ] to see it working.

Password Protection

You may have an area of your site that you wish to be restricted to maybe your own members or subscribers, and there are several ways and levels of security that are achievable using simple techniques.

The simplest way is possibly the application of a form input box to a password request page, into which you type the password. You hit the send button, and then the script checks to see whether the password matches that which has been pre-selected by the owner of the site and put into a data file. If it matches, you are passed through to the next page, if it fails - you are unceremoniously dumped back onto the home page. The downside to this is that the address of the page following the password entry page could be given to a third party who could then byepass the password page by entering its address in the address bar on his browser - and he is in.

A higher level of security - might or might not ask you for a password, but if you are a member or subscriber, you will have been provided with a cookie on registration, and each protected page that you want to visit will in turn check to see that your cookie is in place. If it isn't, again you will be dumped back onto the home page, or in some cases you will be directed to a page suggesting that you subscribe, or become a member. Under this system, even if protected page addresses are given to third parties, if their browser does not have the cookie, they will not be allowed access to any of them. You could try the no-hiccups.com site, which is a home improvement site and see what happens when you try to access the members area without joining. Joining is free of charge, so you might try joining and then you will find you have unimpeded access. You are not asked for a password, but your browser will have picked one up in the form of a cookie. Press [ HERE ] to see it working.

Shopping Carts

We can make these as complicated as we want. A good example can be found at: [  zipvit.co.uk ] who sell vitamins and minerals on-line. If you click on 'Shopping Online' you will go through to the shopping pages which illustrate well how these sites are organised. This shopping page has only one page of products with illustrations, although we can have as many pages as we like. It gathers the items you want to purchase, then passes you through to a Collection page where you can view the products you have purchased together with the cost. The carriage tariffs for various countries are given by a link from the bottom of the Collection page. If you have then finished your selection you then pass to a Form page for your personal details, and requests country of origin. Carriage is added by tariff according to the country, and if you are cookie enabled, when you send the order, a cookie will be added to your browser so that the next time you place an order, your address details will already be entered into the input boxes.

This script does a lot more than can be seen by just placing an order. It also generates a statistics page where the client can view orders received to date by order number, and by country of origin. It also generates year on year data, and collects email addresses for perodic mailshots. It generates a product total so that at the end of the month, the client can tell exactly how many of each product has been sold - for re-ordering, and the search facility that is on the front page and at the top of the first shopping page, records what people have been searching for, thus enabling the client to determine what other products for which there might be a demand.


(a) Statistics mean different things, but here is a script that collects data on search terms used by people to find a web site, and at the same time tells us what web site they came from. A little observation will tell you which hits have come from linked sites or pages, and which have come from search engines.

What we need are the search words used, but the search strings used by some search engines are so long that I have trunkated them so that they fit on to a single line otherwise the data starts to become unreadable.

This is a web site that I have generated myself to give people information about what vitamins and minerals do for us and how they help to keep us healthy. Click [  HERE ] to see the statistics generated.

(b) Another set of statistics can be see on the Statistics of client web pages that I generate for customers. This page is totally self replicating, and I don't have to touch a thing from one year to the next, and details over a twelve month period, how many hits each client site gets each month. There is a client identity reference in red, a total hits column next to it, then in green is the hits for the current month to date, then the past months results, and finally what the total hits had been at the beginning of the current month at the re-set date.

Everything on this page is generated on the fly starting with the welcome date and message, the re-set date generated by recognition of the current month from the date, the data array, including the individual current hit counts, and when the table is loaded each time, it backloads the current table of results to a new file which is named after the current month.

This is quite impressive and demonstrates how fast an array can be generated when it has to load data from about 70+ counters, upload and read a data file, and generate the table from the array, then backload the updated data including the current hit counts from the green column. Two or three clients have some of their own pages with extra counters on, and these can be spotted because they are referenced in dark blue in the red client reference column.

Click [  HERE ] to see the statistics generated.

Still to come

Notice Board
Design a Sign
    .... and any more I can think of

OK - so this page isn't finished yet - come back tomorrow and check again

Previous Page Domain Index
Top of Page
Last updated: April 10th, 2005.
This Page address: http://www.ldb.co.uk/ldb/perl.htm
Published by:  Lichfield Web Design