I heard many people around still saying Perl is great language for CGI. But i think it is not as much as popular as now growing languages such as Python, Ruby.
Is there any solid reason for Perl still being the appropriate language for CGI.
Perl is not a great language for CGI. Or rather, CGI isn’t great.
The Perl language was designed by Larry Wall to make his sysadmin tasks easier. It is interpreted, highly portable, has deep Unix integration, and unparalleled text handling facilities (especially when compared with C). When the Web came around, Perl was at the right place at the right time, and became popular as an easy to learn language which was available on virtually any server. This allowed people to easily cobble together simple forms or other kinds of dynamic content. Originally, many people used cgi-lib.pl
to abstract over the CGI protocol, later CGI.pm
was used.
Today, Perl isn’t used very much in this area, as other languages like PHP have taken over this specific niche. While Perl is a general-purpose programming language that was used for the Web, PHP was specifically built for creating websites via CGI.
While Perl still is a great language, CGI has become unpopular: This protocol requires a new interpreter to be started for each request, which is too slow for anything but low-traffic websites. The FastCGI protocol is better in this regard as one interpreter instance handles multiple requests. Certain servers like Apache have tried to reduce overhead by integrating the languages deeper into the server, via plugins like mod_perl
or mod_php
. They have a ton of issues themselves.
Today, most programming languages define a specific server interface, e.g. Perl has PSGI, Python has WSGI. This interface defines how a server can pass on requests to a web application and allows a variety of efficient or backwards-compatible middlewares.
Web programming today has been irreversibly shaped (no, improved) by the innovative Ruby web frameworks Ruby on Rails and Sinatra. Since then many projects have scrambled to bring this ease of creating webapps to other languages. In Perl, these projects are
- Dancer (basically just a simple way to map routes to templates)
- Mojolicious (a very complete, low-dependency web framework)
- There’s also the older Catalyst framework, but it’s far more complex.
As these frameworks are built on PSGI, they can be deployed via CGI or via any other interface where appropriate middleware exists (there are also a few specialized PSGI servers).
Perl isn’t the only language that has such awesome stuff: Ruby was already mentioned, and Python has a few nice frameworks of it’s own, the most well-known being Django. While PHP is very much invested in being usable via mod_php
without much further ceremony, it too has a number of modern frameworks. Actually, any language that has been used in the past twenty years has some kind of web framework, and Wikipedia has a nice list of them.