Web Teacher Software
web database
Javacript 
Tutorial
CGI tutorial
web 
database consulting
web database training
contact us about web 
database software
press
Hosted Database Solutions
webteacher home
Web Teacher Consulting
CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl

Breaking down the code,
an introduction to Perl.



#*****************BEGIN BODY*************

print "<h1>Thank you for filling out the form</h1>";

$firstname = $value[0];
$lastname = $value[1];
$email = $value[2];
 
print "Your first name is $firstname<BR>";
print "Your last name is $lastname<BR>";
print "Your e-mail is $email<BR>";
 
#***************END BODY******************



There are a couple of things you will notice right away about Perl

  1. Every line ends with a semicolon (;)
  2. Variables always begin with a dollar sign ($).

The first line is pretty straightforward.  print displays whatever follows it on the screen.
As you can see, the text you want to print must go in quotes, and HTML tags are OK.

The readparse subroutine automatically placed the contents of of the HTML form in an array called value.  This makes it easy, because the contents of the first text box is in $value[0].  The second is in $value[1], the third is in $value[2]. Remember, Arrays always start counting with 0.

In the second line we executed this command:
    $firstname = $value[0];
This line creates a new variable called $firstname, and assigns the contents of $value[0] to it.  This means that $firstname now contains the value was typed in the first textbox on the HTML form.

The third and fourth lines are almost identical,
    $lastname = $value[1];
    $email = $value[2];
Obviously, these two lines assign the contents of the second and third text boxes to $lastname and $email respectively.

The last 3 lines of the program print both text and variables to the screen.
  print "Your first name is $firstname<BR>";
  print "Your last name is $lastname<BR>";
  print "Your e-mail is $email<BR>";

Notice that the variable is contained entirely within the doublequotes.  In other languages, such as JavaScript, we would have had to concatonate the text and variables together.  When Perl sees the $ symbol, however, it simply substitutes the contents of the variable.  Nice feature, isn't it?  Note: This is only true for double quotes.  Single quotes take their contents literally.

BACKThis is easy, show me e-mail!


Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room