eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
 ::   Tutorials
 ::   Presentations
Perl & CGI tutorials
 ::   Intro to Perl/CGI and HTML Forms
 ::   Intro to Windows Perl
 ::   Intro to Perl 5
 ::   Intro to Perl
 ::   Intro to Perl Taint mode
 ::   Sherlock Holmes and the Case of the Broken CGI Script
 ::   Writing COM Components in Perl

Java tutorials
 ::   Intro to Java
 ::   Cross Browser Java

Misc technical tutorials
 ::   Intro to The Web Application Development Environment
 ::   Introduction to XML
 ::   Intro to Web Design
 ::   Intro to Web Security
 ::   Databases for Web Developers
 ::   UNIX for Web Developers
 ::   Intro to Adobe Photoshop
 ::   Web Programming 101
 ::   Introduction to Microsoft DNA

Misc non-technical tutorials
 ::   Misc Technopreneurship Docs
 ::   What is a Webmaster?
 ::   What is the open source business model?
 ::   Technical writing
 ::   Small and mid-sized businesses on the Web

Offsite tutorials
 ::   ISAPI Perl Primer
 ::   Serving up web server basics
 ::   Introduction to Java (Parts 1 and 2) in Slovak


introduction to web programming
Perl Inter-Application Libraries  
Good design does not stop with the use of subroutines. Often, several different scripts will be designed to incorporate the use of similar routines. In this case, it makes sense to remove the common routines from the programs and place them in a separate file of routines.

This file can then be loaded as a library of subroutines into each program as needed.

For example, in CGI, most applications will need a form gathering and parsing routine, a template for sending out the HTTP header, and perhaps one to generate template HTML code, such as the following:


In this case, we use library files and require them from the main script. A library file in Perl is simply a text file containing subroutines that are shared by several different Perl scripts. For these library files to be usable by the program, they must be readable by the script and must be in the Perl library path (or its location must be explicitly referenced).

For example, if we wanted to load Steven Brenner's cgi-lib.pl library into our script, we would use the following:

    require "cgi-lib.pl";

When this is done, every subroutine in cgi-lib.pl becomes accessible to the main script as if it were actually written into the script's code. We simply reference a subroutine contained in cgi-lib.pl as we would any other subroutine in the main program.

Previous | Next | Table of Contents