Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Simplest Perl CGI

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

geekyone
Junior Member
*


Posts: 32
Group: Registered
Joined: Apr 2008
Status: Offline
Reputation: 1
Points: 113 (Donate)
Post: #1

Simplest Perl CGI


I started writing a longer tutorial, trying to introduce new users to Perl, but it was lost, so I'll just use the simplest CGI script possible to explain the basics of CGI with Perl for complete novices.

First you need to tell Perl where it is.

Code:
#!/usr/bin/perl -w

The default location as you can see is /usr/bin/perl
You can see the w tag after, which stands for warnings.

Everyone makes mistakes. That's why you need to make sure you have ways to debug your code and figure out what went wrong.

Code:
use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #debugging line

That is what is called a module. What this line does is print warnings, and problems that cause the program to be unable to run.

Code:
use CGI;

This is the module that actually does all the work of printing webpages for you.

Code:
$cgi = CGI->new;

This calls the CGI module and I bet you can guess what it does.

Code:
print $cgi->header;

That prints the HTML header.

Code:
print $cgi->start_html("Hello World");

Code:
This actually starts the HTML, and sets the title as Hello World

[code]
print "<h1>Hello World!</h1>";

Prints the header tag saying Hello to the world.

Code:
print $cgi->end_html;


And finally, if you are too lazy to copy it line by line:

Code:
#!/usr/bin/perl -w

use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #debugging line

use CGI; # CGI Module

$cgi = CGI->new; # Creates new CGI
print $cgi->header; # Prints HTML Header
print $cgi->start_html("Hello World"); # Starts HTML
print "<h1>Hello World!</h1>"; # HELLO WORLD!
print $cgi->end_html; # end HTML

15-04-2008 11:24 AM
Find all posts by this user Quote this message in a reply
ivenms
Administrator
*******


Posts: 2,169
Group: Administrators
Joined: Sep 2006
Status: Offline
Reputation: 14
Points: 4369 (Donate)
Post: #2

RE: Simplest Perl CGI


Great, thanks...

Reputation added.. Smile


Read: General Rules & Policies before posting.
Make Money By Posting | Earning and Exchanging Points | Add Your Links
15-04-2008 04:31 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  MySQL with Perl maddog39 4 573 09-08-2007 07:04 AM
Last Post: walsh
Smile Testing Perl Programs bomber 0 584 19-09-2006 12:39 AM
Last Post: bomber
Smile Storing and Running Perl Programs bomber 0 645 19-09-2006 12:13 AM
Last Post: bomber
Smile Taste of Perl bomber 0 623 19-09-2006 12:11 AM
Last Post: bomber
Smile State of Perl bomber 0 643 19-09-2006 12:09 AM
Last Post: bomber
Smile What Is Perl? bomber 0 603 19-09-2006 12:07 AM
Last Post: bomber

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

lifewithC.Com
SOTM May 2008


Accepting Submissions
for June 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 04-07-2008, 09:39 AM


Copyright © 2002-2008 MyBB Group
Powered By MyBB