Perl and the Common Gateway Interface - out of fashion but still very useful?
Archive - Originally posted on "The Horse's Mouth" - 2009-12-26 09:57:43 - Graham EllisIs the Common Gateway Interface dead? No - it isn't; although my first choice for a new web application these days would be something else (PHP, Java with Servlets, JSPs or a derivative, Python with Django, Ruby with Rails ...), there are often times that I'll have a bit of code that I've run away from the web and I want to run it on-line - and quickly wrapping the code with some CGI stuff will get it available fast.
With CGI, you can take code that's running in any language that your web server supports, and with careful use of the STDIN (a.k.a. pseudo keyboard inputs), environment variables, and (occasionally) command line inputs, you can feel the code with input data as if it was running from the command line. For output, you simply write your code as if you're outputting to the screen / window in a command line based application, and your web server will route that output back to the browser.
I've taken the code from my previous entry here, that looked for a Christmas *something* in all the various railway station names, and put in on line [here]. Easy - or rather fairly easy. In practice, there's a need to add a lot of user documentation, to take away the interaction as all data is fed in at the start, to check that the users have made sensible inputs and to secure the script against people trying to hack in to the server using it, so the code ends up a bit longer that you might have expected. See [here].
We're still covering CGI as part of our Using Perl on the Web course ... and that's a follow on from our Perl Programming course where you can learn the basics.