Tech Support Guy banner
Status
Not open for further replies.

CGI/Perl Tutorials

1K views 6 replies 4 participants last post by  Regicide 
#1 ·
I'm looking for a good Perl/CGI tutorial. Or if anyone knows any good books about this, it would help alot. Thanks!
 
#5 ·
Thanks for the quick responses on tutorials. Now I only have a few questions. What is the differences between CGI and Perl, other than syntax? And which is the better language?
 
#6 ·
In answer to your question let me say that CGI isn't a language - it is an Interface.

The Common Gateway Interface allows for applications to communicate using a "common" syntax. You can have COBOL speak CGI to another application which understands CGI also.

This is a Unix shell script which talks CGI:
#!/bin/sh
# disable filename globbing
set -f

echo Content-type: text/plain
echo

echo $GATEWAY_INTERFACE test script report:
echo

echo argc is $#. argv is "$*".
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = "$HTTP_ACCEPT"
echo PATH_INFO = "$PATH_INFO"
echo PATH_TRANSLATED = "$PATH_TRANSLATED"
echo SCRIPT_NAME = "$SCRIPT_NAME"
echo QUERY_STRING = "$QUERY_STRING"
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH

A Perl example:
#!/usr/local/bin/perl
##
## printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}

You can see a more complex Perl example here:
http://insecurity.org/cgi/cgi_reflect.cgi

Perl is a advanced programming language with as much power and C with 1/10th the coding effort.

CGI.pm is a CGI Perl Module which extends the Perl language so that you have an exposed Interface for writing CGI without having to know all the gory details.

HTH/Bill
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top