CGI stands for Common Gateway Interface, is basically a set of standards that defines how the information is exchanged between the web server and the custom script.
Before proceeding with CGI programming in perl, first make sure that your web server supports the CGI functionality and it is configured to handle any CGI programs correctly. All the CGI programs to be executed by the web server are basically kept inside a pre-configured directory, called as CGI directory and by convention it is named as /cgi-bin. You .cgi extension to all the perl CGI files.
Here is a simple CGI program in perl, give you some basic idea about CGI programming in perl. This is hello.cgi file, kept in /cgi-bin/ directory.
#!/usr/bin/perl print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print '<title>My First CGI Program in PERL</title>'; print '</head>'; print '<body>'; print '<h2>Hello World, This is my first CGI program in PERL</h2>'; print '</body>'; print '</html>'; 1;
Now if you click on the link, hello.cgi, here is the sample output produced: