![]() |
Hello World |
||
|
Before continuing, let's write our first CGI program. Open up your favorite editor (I like XEmacs myself) and create a new file in the cgi-bin directory called hello.pl. Copy the following Perl code into that file:
The first line is known as the shebang, and informs the operating system of the program that can understand this code (perl, in this case). If your version of Perl is installed at another location, you will want to change this line to correspond (eg, under Windows it is common to put #!perl.exe on the first line). The next block of lines simply print out statements, and the last line exits the Perl interpreter cleanly. You should try to run the program outside of the webserver first, to be certain that it works properly:
It should return everything that is printed out in the program. The 'w' flag above tells Perl to perform thorough checks, and to stop if it finds any errors or warnings. Next, we want to make sure the program runs by itself, without having to specify the Perl interpreter explicitly:
Now we are ready to run it through the webserver, so load up your favorite browser and test it out:
The result should look like this: If you don't see what you expect, double-check the syntax of your code, and run through the test from the command line again. Check your error_log and access_log for any possible problems. Congratulations! You've written your first CGI program. All pages written by Craig Kelley unless otherwise specified. Please use the Contact link from the menu to submit changes or suggestions. Permission is given to use this tutorial in any way you wish including re-publishing or "mirroring". The most up-to-date version of this document currently resides at http://inconnu.isu.edu/~ink/perl_cgi. This page updated: May 6, 2002 22:21 |