www.fachtnaroe.ie



Web This site

(Test: CSS  HTML)

Using Perl Online

[Programming Home] [Input (2)] [Process (3)] [Output (1)]

Perl is one of the most widely deployed languages on the web for all forms of scripting. It is available on web servers irrespective of OS platform or hardware.

Output

What you might initially find is that the input -> process -> output method that you have been using at the command line is not available to you. It might seem harder to write a program that asks a question, reads the answer and then gives some output; this is what you've been doing at the CLI and it's what you're most familiar with. So for the time being, we won't deal with input or processing. We'll just make sure we can get some output, by using the traditional first program, Hello World program.

Navigate to:

/var/www/cgi-bin

within our server xen.fachtnaroe.net - there you should find a folder with your username on it. Enter that folder and create the file hello.pl and enter the following code:

#!/usr/bin/perl
print "Content-type: text/html\n\n";

print "<html><body>Hello World!</body></html>";

To run this program, use your browser to open the location:

http://xen.fachtnaroe.net/cgi-bin/your_username/hello.pl

and see what appears on screen. It should be our familiar first program, generating HTML to deliver its traditional message. If you receive any error messages confirm your code is correct. Also make sure that the execute bit is set on the file.

For practice, take your earlier programs square.pl and star.pl and copy them into your cgi-bin directory. Convert them to run as web scripts. Note that the perl location directive and the web content type instruction must always come first in these scripts:

#!/usr/bin/perl
print "Content-type: text/html\n\n";

Do the shapes appear as expected? Can you generate other output? Remember that your perl script is writing HTML - which you are familiar with - so experiment: change code and colours; see can you create tables & other web effects. See what other programs you can port from the CLI environment to the CGI environment.

Next, getting some input...


[Programming Home] [Input (2)] [Process (3)] [Output (1)]

Last updated: 20120108-17:13
back to top
Fachtna Roe, Senior College, Central Technical Institute, Clonmel, Ireland.