Some quick Perl basics
Perl is a multipurpose language. It has lots of other uses besides
what we are doing. So, if you are looking to learn Perl and all of its
uses, go here.
Likewise, if you know Perl already, you can skip this
section and go to "Getting Started - The HTML".
All variables start with a $. Well, that's not true. Perl has other
types of variables, we just won't be using them. As a side note, if you
are interested in the Perl language itself, visit your favorite computer
bookstore and ask for the "Camel book" -- it's published by
O'Reilly, has
a camel on the front cover, and is the definitive reference on Perl.
Variables can be as descriptive as you would like.
Examples:
$Customer
$Employee1
$Phone_number
To open a file, use the open command.
Syntax:
open(TAG, "path/to/file")
or die "Message to print when
the file can't be opened";
|
TAG: A short phrase for referring to this file in other parts
of the program.
path/to/file: This is where you need to know the path to your
douments. In most cases this will just be the file's name (see example).
This path varies widely on different systems. If
you are not sure, contact your system administrator.
Message to print when the file can't be opened: Self explanatory.
Use \n to print a new line. $! Prints the error message. |
Example:
open(THEATER, "theater.data")
or die "We could not open the Movie
Theater Information file.\n
Please email the webmaster
with the following
information:\n$!\n";
Note: Our examples are word wrapped for
formatting purposes. All Perl lines end in a semicolon, so when
using this code in your programs, make sure each line ends in a
semicolon.
We'll be reading input from a file. Our file will have text seperated by
semicolon. If this bothers you (or more importantly conflicts with some
of your data, use a comma or some other character. After each file is opened,
change the semicolon in the split statement to that character.
People will use your Perl program just as they do any HTML file - so
you'll need to print your output in HTML. To do this:
Print >> EOF;
<PUT HTML HERE, USE AS MANY
LINES AS NEEDED>
EOF;
Also note: before the first part of your output, insert this line.
print "Content-type: text/html\n\n";