CGI.pm is a large and once widely used Perl module for programmingCommon Gateway Interface (CGI) web applications, providing a consistent API for receiving and processing user input. There are also functions for producing HTML or XHTML output, but these are now unmaintained and are to be avoided.[1] CGI.pm was a core Perl module but has been removed as of v5.22 of Perl.[1] The module was written by Lincoln Stein[2] and is now maintained by Lee Johnson.
History
In 1993 the CGI specification was formalized to standardize how web servers could execute external programs and scripts; instead of just serving static files, they could generate dynamic content. In response to individual requests, CGI scripts could process user input and generate new HTML pages on the fly.[3]
CGI.pm was written by Lincoln Stein to simplify not only the process of correctly capturing information and data sent to a web site, but also generating the new HTML content in the response.
Before the advent of this module, creating a CGI script from scratch required writing code that could:
- Parse environment variables (to get request data)
- Decode URL-encoded form data
- Parse query strings
- Generate proper HTTP headers
- Escape HTML output to prevent errors [3]
In contrast, the various methods and functions available in CGI.pm allowed one to create a Perl script that automated a great deal of the more tedious coding (see examples below). Many of the largest and most well-known web sites and Web Apps relied on CGI.pm when they were first launched: EBay, IMDb, CPanel, Slashdot, Craigslist, Ticketmaster, Booking.com, TWiki, Bugzilla, Movable type, and LiveJournal.[4] However, in the interim, as web development toolkits expanded and evolved over time, these sites eventually migrated to using other programming languages and frameworks.,[5][6]
Examples
Here is a simple CGI page, written in Perl using CGI.pm (in object-oriented style):
#!/usr/bin/env perlusestrict;usewarnings;useCGI;my$cgi=CGI->new;print$cgi->header('text/html');print<<"EndOfHTML";<!DOCTYPEhtml><html><head><title>ASimpleCGIPage</title><metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/></head><body><h1>ASimpleCGIPage</h1><formmethod="post"enctype="multipart/form-data">Name:<inputtype="text"name="name"/><br />Age:<inputtype="text"name="age"/><p><inputtype="submit"name="Submit!"value="Submit!"/></form><hr/>EndOfHTMLif(my$name=$cgi->param('name')){print"Your name is $name.<br />";}if(my$age=$cgi->param('age')){print"You are $age years old.";}print'</body></html>';This would print a very simple webform, asking for your name and age, and after having been submitted, redisplaying the form with the name and age displayed below it. This sample makes use of CGI.pm's object-oriented abilities; it can also be done by calling functions directly, without the $cgi->, however the necessary functions must be imported into the namespace of the script that requires access to those functions:
#!perluse strict ; use warnings ; use CGI qw/ :standard / ;imprimir encabezado ( 'texto/html' );# ... Salida HTML igual que el ejemplo anteriorif ( my $name = param ( 'name' ) ) { print "Tu nombre es $name.<br />" ; }if ( my $age = param ( 'age' ) ) { print "Tienes $age años." ; }imprimir '</body></html>' ;Nota: en muchos ejemplos , $q , abreviatura de consulta, se utiliza para almacenar un objeto CGI.
Véase también
Referencias
- 1 2 "CGI - Manejar solicitudes y respuestas de la Interfaz de puerta de enlace común - metacpan.org" . metacpan.org .
- ↑ Stein, Lincoln D. (1998). Guía oficial para la programación con CGI. pm: [ el estándar para la creación de scripts web ] . Nueva York: Wiley. ISBN 978-0-471-24744-9.
- 1 2 Coar, Ken AL; Robinson, David (octubre de 2004). La interfaz de puerta de enlace común (CGI) versión 1.1 (Informe). Grupo de trabajo de ingeniería de Internet . Recuperado el 24 de diciembre de 2025 .
- ↑ "Todo el software es heredado" . leejo.github.io . Consultado el 24/12/2025 .
- ↑ Stevenson, Michael. "Perl y el nacimiento de la web dinámica | Opensource.com" . opensource.com . Consultado el 24 de diciembre de 2025 .
- ↑ Stevenson, Michael (2 de octubre de 2018). "Tenerlo todo: Larry Wall, Perl y la tecnología y cultura de la web temprana" . Internet Histories . 2 ( 3–4 ): 264–280 . doi : 10.1080/24701475.2018.1495810 . ISSN 2470-1475 .
Enlaces externos
- CGI.pm – en CPAN