Background

In older times, code to parse form input was usually written in C. While it executed very quickly, it was also tricky to program - a simple parsing script could easily take up fifty lines or more. The main reason for the length was that C was not designed specifically for the web so there was no pre-written code to make common tasks easier, so you had to do everything yourself.

For example, in a HTML form with two text boxes, "FirstName", and "LastName", where the user had entered "Joe", "Blow", the C program would receive "FirstName=Joe&LastName=Blow". It would then have to read the string in order to find out what variables are there and what they are set to. Of course, this was a great deal better than the situation before - HTTP is a stateless system, which means it saves no data at all across pages, and therefore even being able to use C to send data across pages was a big step forward.

This problem was solved somewhat by an easier language called Perl, which is a somewhat loose acronym for "Practical Extraction and Report Language", or "Pathologically Eclectic Rubbish Lister", depending on whom you speak to. Perl, originally invented as a generic text-processing language, enabled HTML form-parsing and other fancy tricks to be within reach of even novice programmers.

The Perl design process was simple: you had a Perl script performing all your functionality for a particular page on your web site, into which you embedded any HTML output that was necessary. Perl provided a large variety of functions designed to simplify any task you could dream up, which made it immensely popular with developers.

This was followed up by the CGI.pm module for Perl, which automatically converted values passed from a form into variables, eliminating the need to hand-parse the variables string. A Perl script to parse the same FirstName/LastName form as before could easily take under twenty lines to write, and would be much easier to read.

Even though it was a big step forward for web development, Perl was still far from perfect. Its "one language fits all" thinking meant that it wasn't truly designed for the web, and many Perl programmers placed a large emphasis on "one-liners" - one line of probably confusing code that performed a certain task - as opposed to structured, easy to read programming.

Perhaps the largest drawback was that Perl was Perl-centric. That is, in order to output HTML content, you had to embed HTML inside the Perl.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Early versions of PHP >>

Previous chapter: History

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.