How to Write a Perl Script to Process a Form

The Perl language provides you with the ability to create dynamic Web pages. Perl is an older language that is not used as often as PHP, but you can run Perl scripts in a CGI folder for form processing. Identify the form variables in the main HTML form, then process the form data by either storing the information or displaying it to your users.

Instructions

    • 1

      Click the Windows "Start" button and type "notepad" into the search field. Press "Enter" to open the text editor.

    • 2

      Create a CGI variable and assign the variable to the CGI class. This class allows your Perl scripts to use the CGI engine on your Web server. The following code creates the variable:

      use CGI;

      $p = new CGI;

    • 3

      Retrieve the form values. The following code shows you how to retrieve the form's "fname" and "lname" input controls:

      $fname = $p->param('fname');

      $lname = $p->param('lname');

      You create a new variable for each form element passed to the Perl script. In this example, the user's first and last name are sent to the script.

    • 4

      Process the form information. You can use Perl to manipulate the data in any way you need to process the information. In this example, the form information is displayed for the user to verify the data:

      print "Content-type:text/html\n\n";

      print "Please verify your information\n\n";

      print "Name: " + $fname + " " + $lname;

Related Searches:

References

Comments

Related Ads

Featured