Table of Contents

  Main
    -Home
    -Advertising
    -Contact Us
    -Updates

  Perl Overview:
    -What is Perl?

  Getting Started:
    -Installing Perl
        / Unix
        / Windows

  Writing Code:
    -Hello World!
        / Basic Output
        / Adv. Output
    -Variables
        / Scalar
        / Arrays
        / Joining Arrays
    -File/Directory
        / Opening
        / Saving
        / Modifying
    -Subroutines
        / Calling
        / Feeding






2.1 - Hello World!
  1. #!/usr/bin/perl
  2. ###############
  3. print "Content-type: text/html\n\n";
  4. print "Hello World!";
  5. exit;

Now going through, line by line, i will break down what everything means.


# Line 1

The very first line of EVERY perl program needs to declare the path to the perl interpreter. In otherwards, this path needs to point to whatever directory PERL is installed in on your system. known as pound(#)-bang(!) followed by the path to perl.

Wondering where perl is installed on your server?

If you have shell access (telnet, ssh) you can type the following command: whereis perl

Otherwise, you will most likely find perl installed to the following dirs (on most systems):
/usr/bin/perl
/usr/local/bin/perl

[ Back To Top ]
# Line 2

Line 2 simply contains a bunch of comment signs (aka remarks in other languages) Commenting your code can be a big help, especially when making future modifications on your scripts, or someone else needs to go through later on to perform updates to your scripts. It also helps people figure out what in the world you are doing.

[ Back To Top ]
# Line 3

This line of code tells the browser how you want to display your output of your script. In our case, we will only be outputing basic text and html. Below I have listed a few other possible alternatives:

- Gif/Image
- Blah

[ Back To Top ]
# Line 4

This is one of the classic output examples. When the script is ran, the following will be displayed: Hello World!

To output data to the screen, simply type print "";

And you place all text you would like outputed to the screen within the two quotes, followed by a semicolon. NOTE: perl is very sensitive, which means if you forget one quote, or one semicolon, your script will return a server error, and not run.

FAQ: How do I output the following HTML tag which contains quotes? <font face="arial" size="2">Size 2 Text</font>

Solution:

In order for perl to properly format the outputed data you must include a \ before each quote you would like ignored. Eg: <font face=\"arial\" size=\"2\"> Size 2 Text</font>

So your code would look like:
print "<font face=\"arial\" size=\"2\">Size 2 Text</font>";

And when your html code is displayed by the script the backslashes won't even show up.

[ Back To Top ]
# Line 5

The text 'exit;' simply tells perl to literally exit the program, or kill the script. Forcing your script to stop.

Questions? Comments?
Visit Our Web Forums

A1Javascripts
A heap of free javascripts to enhance your site!

123Webmaster
The largest directory of free webmaster resources on the planet!

1-Click-Clipart
The most popular free clip art and web graphic sites on the web!

Free-Clip-Images
A monstrous collection of free graphics including icons, lines, backgrounds, clip art, animated gifs, and more.

FreeWareFiles
Download tons of FREE Software! Games, Screen Savers, Utils, and more!

httpCITY
25 megs of free webspace; httpcity.com/YOU!

PerlAccess
Learn perl, or to download free, original perl scripts.