Introduction to Perl Scripting
Test #5: Does CGI work? In order to test CGI, we need to create a program that will print an HTML page. To do this, I am going to use Perl scripting, but this can be done in any language. Here is a simple Perl script that prints 'Hello Dean!':
print "Hello Dean!\n";
Type this into a file called 'hello.pl' and then save and exit emacs. The first line, #!/usr/bin/perl, tells the program loader which scripting language program to use to parse and execute this file. The next two lines are good for code development because they tell the program parsing this file to report all warnings and errors. The 'print' line does all the work! Note that the '\n' in the print statement means 'newline'. Also note that every line of Perl code must end with ';'.
Next, we need to make this file 'executable', so we can run it by itself. This is possible because the first line, #!/usr/bin/perl, defines which scripting language interpreter to use. To make this script executable, run the following command: chmod u+x hello.pl. The chmod command is used to set file mode bits. The u+x argument tells chmod to set the "user execution" bit on 'hello.pl' file. Now we can execute the script, like this:
ubuntu@ubuntu:~$ emacs -nw hello.pl
ubuntu@ubuntu:~$ chmod u+x hello.pl