I am learning Perl and trying to understand the difference between Perl and CGI. I found some definition from this website which says that,
"It is possible to set up the HTTP server so that whenever a file in a certain directory is requested that file is not sent back; instead it is executed as a program, and whatever that program outputs is sent back for your browser to display. This function is called the Common Gateway Interface or CGI and the programs are called CGI scripts."
So my question is, not only CGI script will be sent as a executed file, all other server script languages will be sent as executed file from the HTTP server.So, what is the main purpose of CGI?
I eagerly want to know the answer since I am really very confused. This question might be stupid one but I need to know the answer.
For example:
#!/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;
If I save it in both .pl
and .cgi
extension and run both the programs, I get the same output. Then what would be the difference between cgi script and perl ?.