Sometimes, we use a particular language for an application just because it is there. That was the case when I was developing an online resume submission system originally using Perl. After I thought about it, I realized that PHP would be much more efficient in this application. What follows is my comparison of PHP to Perl for handling online forms—and why, for me, PHP was the clear choice.

The amount of code
The first difference is the amount of code needed to accomplish the task. When using Perl to parse form data, you use a standard set of parsing instructions, based on the incoming form data and the METHOD type (POST or GET). As you can see in Listing A, this code is longer than it needs to be to extract data.

You may be asking yourself, “Why so much code?” Well, in Perl, a large amount of translation and converting goes on, but PHP offers a cleaner way to store and retrieve form data. For example, consider the PHP code in Listing B.

Here, the “POST” equivalent is $HTTP_POST_VARS [name], and the “GET” equivalent is $HTTP_GET_VARS[name]. When the user submits this form, the user’s input, “resumesender”, is stored in the $HTTP_POST_VARS [resumesender] location, where it can be used throughout the entire Web site at a later time to populate values in a form or, as I use them, to populate the fields of the e-mail system that sends the resume to the HR department. This latter use is shown here:
$formVariableName = $HTTP_POST_VARS [resumesender];
$recipient = $formVariableName;
$subject = “TECHRepublic is the best”;
etc, etc…

Populating data fields
PHP is also clearly superior when it comes to processing forms and populating data fields after the processing has occurred. But don’t get caught off guard. I recommend that you start out with some very basic forms like the one shown above and progress from there. It can become challenging once you step into the multipart and multifunctional forms.

More fun with forms
Another way to make forms easy and fun to develop is to use arrays in the form variables context. Listing C  illustrates this approach.

Arrays provide an efficient manner of processing a form with multiselect data fields. They’re also great for database select queries that are pulling real-time data and serving it to the user.

My vote for PHP
Perl just seems too labor intensive to warrant its use in large applications—at least now that we have PHP, that is. I still use Perl for passwords on UNIX systems, but I find that Perl is just not as much “fun” as PHP. Of course, that’s only my opinion as a fellow programmer. I should also mention that after designing corporate Web sites for almost seven years, I feel that PHP is the way that all Web masters should develop dynamic content. It is just an overall better experience for everyone involved.