PDA

Click to See Complete Forum and Search --> : part 1 of CGI.pm


a_420_hacker_24
September 19th, 2002, 11:49 PM
Hello all. I decided to start a tut on the great perl package called CGI.pm
The cgi.pm was designed to help web developers create cgi scripts, for dynamic content.
I’m assuming that you have 5.6.1 and a server that has a working cgi-bin and a decent understanding of html (form, and buttons tags).

CGI = Common Gateway interface

Ok first we will start with a simple form example .

So you have a form that looks like this :

<html>
<head><title>Form</title></head>
<body>



<form action=”/cgi-bin/name.pl” method=”get”>


Please enter your name


<input type=text name=name>
<input type=submit value=submit>
</form>
</body>
</html>

if you notice the name of the form field is name.
Now that we have a form to get he information lets get into processing the users information in this case the name.


#!/usr/bin/perl
#name.pl
#path to perl

use strict;

use CGI qw/:all/;
#This calls the CGI.pm for use in the script
#the “/:all/” loads all the options for the packages

print “Content-type: text/html\n\n”;

my ($name);
#sets the variables for use

$name = param(‘name’);
#CGI.pm uses the param to get variables from the
#script
print “Hello $name”;
#print the Hello <name>

as you can see getting information is a whole lot easier with this package.
It also has great html options built in
(I should also say the there is a OOP and a funtion drivin way to use CGI.pm I tend to use the funtion method).

#!/usr/local/bin/perl
use CGI qw/:all/;
print header,start_html('Html in perl');# starts the html page
h1('hello from perl'), # = <h1></h1> tags
p(‘I will never use html again’), # =

tags
end_html; #ends the html

-------------------------------------------------------------------------------------
the html would be about the same amount in lines………………………

I will continue this soon.