ActivePerl Basic Syntax

Basics of ActivePerl - Part 2

Chrys Forcha
Introduction
This is part 2 of my series, Basics of ActivePerl. In this part of the series, I give you the basic syntax of ActivePerl. As I said in the previous part, ActivePerl and Perl are almost the same thing.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

Statement
A statement in ActivePerl is a short piece of code that ends with a semicolon. An example is:

print "Hello World!\n";

This statement sends the tag, "Hello World!\n" to the browser.

Comments
You should have comments in your code. Comments are not executed. Comments are to remind you later of why you typed a particular piece of code. In ActivePerl, you generally have a comment in a single line; something like:

#This is a comment.

You begin each comment with the hash, # character. Your code is executed by the interpreter at the server to perform a task, such as send a web page to the browser. When the interpreter sees the # character, it ignores ever thing that is on its right. That is it does not execute what is on the right of the # character.

Comment Example
Type the following in a blank page of a text editor:

use strict;

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

print "\n";
print "\n";
print "Hello\n";
print "\n";
print "\n";
#Talking about a man.
print "I am a man.
\n";
#Talking about a boy.
print "He is a boy.
\n";
print "\n";
print "\n";

Save the file as comment.pl in the cgi-bin directory. You web server should be running; if it is not running, start it. Type the following at the address bar of your browser and click Go, http://localhost:8000/cgi-bin/comment.pl ; you may not need :8000. You should see the following at your browser:

I am a man.
He is a boy.

In the comment.pl script, you have two comments, which are "#Talking about a man." and "#Talking about a boy.". Since these are comments in the ActivePerl code, they do not appear at the browser. The ActivePerl interpreter at the server does not send them to the browser. To prove this, right click at the resulting web page of your browser, then click View Source or View Page Source (or anything similar) to see the HTML web page code. If you do this, you will not see ActivePerl comments in the HTML code.

String
If you see any text in double or single quotes in an ActivePerl code, that text is called a string. In this and the previous part of the series, we have seen strings only in double quotes. We have not yet seen strings in single quotes. You will see that soon.

Let us end here for this part of the series and continue in the next part of the series.

Chrys

Published by Chrys Forcha

I have more than 10 years experience in computer programming, software, electronics and telecommunications. I have a First Degree in Electronics and a Master's Degree in Technical Education. As well a...  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.