PERL - Before you begin
This tutorial will be covering the PERL syntax and should provide you with a very solid foundation of PERL
for you to build upon. It is recommended that before you start walking through our tutorial that you have a
general understanding of Web Development as well as some background knowledge of HTML and CSS as our
tutorial is directed toward Web programming.
We will be incorporating our PERL scripts with HTML, CSS, and PHP so if you are unfamiliar with any of these languages, it may be a good idea to touch base with the tutorials offered here, or elsewhere for that matter to familiarize yourself with the code we offer.
Created in 1987 by Larry Wall, the UNIX based language has evolved into a powerful tool for the internet. It was designed as a quick-fix patch program for UNIX based systems. The language is very simplistic, offering optimum flexibility, perfect for short, straightforward scripting.
First things first, you must have PERL 5.005 installed on your web hosting machine. Version 5.005 is
available for download via Perl.com, just follow the download links. They also offer installation help for a wide
variety of operating systems. We suggest you direct any installation help to the experts there.
A PERL script can be created inside of any normal simple-text editor program. There are several programs
available for every type of platform. There are many programs designed for programmers available for
download on the web.
Regardless of the program you choose to use, a PERL file must be saved with a .pl (.PL) file extension in
order to be recognized as a functioning PERL script. File names can contain numbers, symbols, and letters but
must not contain a space. Use an underscore (_) in places of spaces.
With PERL installed we are ready to dive into our first script. There are a few elements every PERL script must contain in order to function. Open up your favorite simple text editor, the file extension for PERL scripts is .pl. Save your files with this extension.
The comment points to the installation path of PERL, usually /usr/bin/perl. If not, you can locate the directory tree to PERL somewhere in the documentation of your web server, or email your web host and they can specify your PERL installation directory.
Because we are working in a web environment we are sort of jumping ahead of the game. We have to
introduce some HTTP headers so that PERL understands we are working with a web browser. To do this we
have to run another line of strange code called an HTTP header as you may have guessed. It looks something
Now it is time to upload your firstscript.pl to your web server and execute it. After you upload your file be sure to CHMOD the script file and allow anonymous execution priviledge, generally a setting of 0755 works perfectly.
If you are using an FTP program to upload your scripts, set the upload type to ASCII or "Text". This setting
prevents the mysterious addition of random characters that sometimes happens when copying files across
different operating systems. Learning to do this prevents hours of headaches and frustration.
PERL follows a very specific syntax not unlike other programming languages. It is important to develop good syntax habits as it will save you from having to debug things later, not to mention save yourself from eye strain and mind numbing headaches.
A great tip for large scripts containing a vast number of variable names it is best to be consistent with your
case sensitivity and maybe even develop a system for naming variables that makes sense to you. For the
majority of us programmers, capitals are simply not an option.
$VAriaBLE_NAmES = "string";
$LIKe_tHESE = "Another String";
$ARe_HArd_to_Type = "A Third String";
As with any programming language, PERL offers an escape from your code via the '#' sign. Any words, spaces, or marks after a pound symbol will be ignored by the program interpreter, offering you the coder, a chance to place reminders to yourself about your code. It's a great way to note specifics of your code to yourself or others viewing your code/script. Comments are necessary for any script you wish to publish to others or make readily available.
This comment is extreme and overdone, you might see more comments like this in scripts that are offered
free on the internet. Often programmers will include a large commented section as an installation or set-up
guide included right there in the script itself.
In PERL we use the backslash (\) character to escape any type of character that might interfere with our code. For example there may become a time when you would like to print a dollar sign rather than use one to define a variable. To do this you must "escape" the character using a backslash (\).
print "Content-type: text/html \n\n"; #HTTP HEADER
#CREATE STRINGS WITH ESCAPING CHARACTERS
#PRINT THE STRINGS print "$string<br />"; print "$email<br />";
Now bringing you back...
Does that email address look wrong? Try again with a different email.