Q1: | How do I create many modules, and group them together by name? |
A1:
| Perl groups module names by using :: to separate each grouping from least specific to most specific. For example, under File there are modules called File::Find and File::IO—both are related to files, but perform different functions. To create your own grouping for a module named MyModules::File::FileInfo, you need to create a directory called MyModules, and under that a directory named File, and under that a file named FileInfo.pm where your module code will go. |
Q2: | I want to put my modules someplace else, separate from the programs. How can I do this? |
A2:
| Perl uses an internal array called @INC to determine where to search for modules. To look for modules in another directory, there's a helper module called lib that will cause perl to look elsewhere for modules. To look for modules in \home\mymodules use this at the beginning of your program:
use lib '\home\mymodules';
For more information, type perldoc lib. |
Q3: | Most of my module users will import large groups of subroutines. This will make my use line very long. Is there a remedy? |
A3:
| Yes. You can choose to collect a group of module subroutines or variable names together and export them as a group. Use the hash %EXPORT_TAGS instead of (or in addition to) @EXPORT_OK. The keys to the hashes are group names; the values are an array reference of the names themselves. The Exporter module manual page has more information. |