Script Wysardry
Adapting Perl CGI Scripts

Perl CGI Script Tutorial 2 - Your First Script.



Home / Script / Tutorial 2

Back | Next

First steps

Before we start on scripts written by anyone else there are a couple of things you will need to learn how to do first.  These are uploading in ASCII (text) mode and changing file permissions with the CHMOD (CHange MODe) command.

With that in mind we need a very simple script that is known to work at Spaceports without modifications.

Open up your text editor, ensure that word wrap is turned off, then copy and paste the following code into a blank document:-


#!/usr/bin/perl
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

# hello.cgi -- use to practice uploading and permission setting

print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n";
print "<BODY>\n";
print "<CENTER><H1>Hello World!</H1></CENTER>\n";
print "</BODY>\n";
print "</HTML>\n";


Now save the file as plain text with the filename hello.cgi - you may need to put quotes around the filename to prevent your editor adding .txt to the end of it, thus saving as hello.cgi.txt instead.  Save it as "hello.cgi" if this happens.

Check the properties of the file if you aren't sure.

Where you save this on your drive is up to you, but I suggest using the same directory structure on your hard drive as you intend to use with the online version.  Put it in a directory called scripts or something to keep it separate.  Any practice scripts you create can then be kept away from those you download.

As a beginner, it is a good idea to get into the habit of keeping each script in its own directory if it has multiple files.  If you save multiple scripts to the same directory you will most likely overwrite existing files with the same name.  For basic individual scripts, you can put them together though.

Site Menu

Bravenet

Section Menu


Copyright © 2000-2003 Wysardry

Most recently updated on 11 May, 2003

Home / Script / Tutorial 2

Back | Next


Please feel free to contact us with any comments or suggestions
Adapting Perl CGI Scripts
Script Wysardry

This site is hosted by Spaceports