internet.com

Go to WebDeveloper Home


hm-v6-139x61.gif

Database Journal: The Knowledge Center for Database Professionals

find a web host with:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
jobs

Get FREE Development Info via your Email!

The Webdeveloper channel
FlashKit
GIF.com
HiermenusCentral
webdeveloper Jobs
Java Boutique
JavaScript.com
JavaScript Source
ScriptSearch
StreamingMedia World
WDJ
WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com

internet.com
Internet News
Internet Investing
Internet Technology
Windows Internet Tech.
Linux/Open Source
Web Developer
ECommerce/Marketing
ISP Resources
ASP Resources
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers

internet.commerce
Be a Commerce Partner
Compare Prices
Prepaid Phone Card
Promotional Golf
Logo Design
Phone Cards
Promotional Pens
PDA Phones & Cases



C G I  P E R L
WebDeveloper.com

Beginners Guide to CGI in Perl
(Part 2)

By Nathan Poole

Obviously we can't just jump right into programming. We need to teach a new basics, if you have a problem with any example click the linked * beside the example for a further explanation.

Discussed is the following, think of it as 4 easy lessons. There are hundreds of Perl commands, we're going to use 4 to begin with, and we're going to make a program with them.

  • Perl Path
  • Printing
  • Defining Variables
  • Comparing with if statements

PERL PATH


When a server installs Perl on their machine, it's given a directory to be stored in. Just how your Perl program was installed in C:Perl, their Perl would most likely go in a directory /usr/bin/perl. You refer to this so your program knows where to find Perl. This obviously is the first thing in your program. Since I'm assuming everyone using this tutorial is on Windows, we don't need to define these when we're using your Windows Perl, but we will just to get you in the habit. At the top of your program you'll want to type:

#!/usr/bin/perl

This is where Perl is usually installed on a server. If you seem to be having problems when we jump into CGI check the troubleshooting section of this article and there you can find out how to check your perl path.

Printing

Of course our first program will have you print "Hello World!" on the screen. So you'll need to know how to print (even though the example will be shown later).

print "Whatever you want to print here";

As simple as that. Like many HTML tags you need to show Perl when to start printing, and when to stop. We accomplish this by using quotations, and then we end the statement in a semi-colon.

Defining Variables

When programming, you may need to stor some information somewhere, and unfortunately Perl just can't keep it in it's nooks and crannies until you need it. So what we do is input that information into what's called a variable. A variable is assigned with a number sign ($) and holds that information until you need it (if at all). For example...

$myname = "Nathan Poole";

And now, until someone deletes my program, the characters $myname means "Nathan Poole" and nothing more. You want to name your variable names something related to what information it will hold. So $myname seems justified.

Comparing with if Statements

This will be the hardest thing we'll discuss here, so you may want to pay a little closer attention. Sometimes you'll need to check if a variable equals something in particular. For example, if I had the following...

$myname = "Nathan Poole";

And perhaps I needed to check that information. I would use an if statement. It looks a little something like this.

if ($myname eq "Nathan Poole") {
print "Hello Nathan, yes, I know you quite well";
}

Think of it like this -- the comparison portion of our program is in between brackets. And the ACTION part (the section that our program is to do something after it decides if something is true or not) is in between braces. Now that example would check if $myname equals Nathan Poole. And we know it does so after Perl realizes that, it will print out "ello Nathan, I know you quite well". In fact, let's give that a try.

[ Click here to move to the next part of the article ]

Fast Jump to Anywhere on WebDeveloper.com:


Contact the WebDeveloper.com staff

Last modified: 20

 

Refresh Daily
Join Editor-in-Chief David Fiedler The Editor With No Time and find truth, justice, and a clue or two.


Browse by Category
[ Site Map ]

ActiveX / VBscript
Animated GIF Archive
Browsers
CGI / Perl
Database Connectivity
Design / Graphics
E-Commerce
HTML-Advanced: DHTML, CSS
HTML / Site Authoring Tools
Intranet/Groupware
Java
JavaScript
Multimedia: Audio / Video / Streaming Technologies
Opinions
Refresh Daily: Editorial Column
Security
Servers & Server Tools
Site Design / Graphics
Site Management / Marketing / Log File Analysis
Tutorials
VRML / 3D
XML




JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers