- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
First CGI Program using Perl
Here is a simple Perl CGI program available in file called hello.cgi. This file has been kept in /cgi-bin/ directory and it has the following content. Before running your CGI program, make sure you have change mode of file using chmod 755 hello.cgi UNIX command.
#!/usr/bin/perl print "Content-type:text/html\r\n\r\n"; print '<html>'; print '<head>'; print '<title>Hello Word - First CGI Program</title>'; print '</head>'; print '<body>'; print '<h2>Hello Word! This is my first CGI program</h2>'; print '</body>'; print '</html>'; 1;
Now if you click hello.cgi link then request goes to web server who search for hello.cgi in /cgi-bin directory, execute it and whatever result got generated, web server sends that result back to the web browser, which is as follows −
Hello Word! This is my first CGI program
This hello.cgi script is a simple Perl script which is writing its output on STDOUT file, i.e., screen. There is one important and extra feature available which is first line to be printed Content-type:text/html\r\n\r\n. This line is sent back to the browser and specifies the content type to be displayed on the browser screen. Now you must have understood basic concept of CGI and you can write many complicated CGI programs using Perl. This script can interact with any other external system also to exchange information such as a database, web services, or any other complex interfaces.
- Related Articles
- First CGI Program in Python
- Perl CGI Environment Variables
- Perl First Program
- Difference between CGI and Perl
- How to write first Hello World program using CGI programming in Python?
- How to use Cookies in CGI in Perl?
- Using Cookies in CGI in Python
- Hello World using Perl.
- Passing Checkbox Data to CGI Program in Python
- Creating and Using Objects using Perl
- How to run Perl Program?
- Passing Radio Button Data to CGI Program in Python
- Passing Text Area Data to CGI Program in Python
- Using GET Methods in Perl
- Using POST Methods in Perl
