Is there a way to include "pre-written" code in a Perl script. For example, I have repeatedly coded the necessary information to access the database (including user name and password) in a number of programs. Is there a way to write this information one time in one file and "include" it in all the programs accessing the database?

It sounds like you want to create a library. Libraries allow you to keep frequently used code in a separate file that you can "include" (using your ssi analogy) as needed.

To do this, simply put your subroutines into a separate text file, such as library.pl (make sure there's a 1; as the last line so your library returns a "true" value), and require the library when you need access to the subroutines. Suppose your library.pl had a subroutine named verify_username, which you use to check usernames. You can use the following;

For best encapsulation, the actual code in library.pl should all be enclosed within a subroutine, so you don't inadvertantly reassign any variables from your program. You may also wish to further encapsulate your subroutines by passing variables to it, rather than relying on remember what the variable names were. For example, in your program, you can use:

In the above, I used the standard pass/fail scheme by giving pass a true value (1), and fail a false value (0).

So yes, you can not only set aside regularly used code, but you can also enclose (encapsulate) them into subroutines that will not affect the rest of your program... with the great side effect of not having to remember the variable names used in each subroutine.

Thanks for your reply. But I don't need to actually execute the code, just "drag" it in. I'm looking for something like the <--#include --> statement that instead of bringing in HTML code will bring in Perl code snipets I've previously written.