Sharing Code Among Scripts

In some cases it’s impractical to bundle the code to handle all of your requests into one giant script. However, some of the code associated with your group of scripts is probably useful in more than one of them. Bundling up the common code into a library of sorts is an alternative to building complex scripts that handle multiple types of requests.

You can write any number of files containing subroutines that can be called from the programs that use them. Whenever you use the use function built into Perl, you are in fact loading an external library. You’ve seen the CGI module (a library that is written in a specific way) used in every CGI program in this book so far. The use function imports a module, and depending ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.