Consider that I have 100 Perl modules in 12 directories. But, looking into the main Perl script, it looks like 100 use p1 ; use p2 ;
etc. What is the to best way to solve this issue?
相关问题
- $ENV{$variable} in perl
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
- How do I get a filehandle from the command line?
相关文章
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- What is a good way to deploy a Perl application?
- Speeding up Selenium Webdriver
Putting all of the use statements in a separate file as eugene y suggested is probably the best approach. you can minimize the typing in that module with a bit of meta programming:
Put all the
use
statements in one file, say Mods.pm:and include the file in your main script:
I support eugene's solution, but you could group the
use
statements in files by topic, like:And of course you should name the modules and the mod-collections meaningful.
It seems unlikely to me that you're
use
ing all 100 modules directly in your main program. If your program uses a function in module A which then calls a function from module B, but the main program itself doesn't reference anything in module B, then the program should onlyuse A
. It should notuse B
unless it directly calls anything from module B.If, on the other hand, your main program really does talk directly to all 100 modules, then it's probably just plain too big. Identify different functional groupings within the program and break each of those groups out into its own module. The main reason for doing this is so that it will result in code that is more maintainable, flexible, and reusable, but it will also have the happy side-effect of reducing the number of modules that the main program talks to directly, thus cutting down on the number of
use
statements required in any one place.(And, yes, I do realize that 100 was probably an exaggeration, but, if you're getting uncomfortable about the number of modules being
use
d by your code, then that's usually a strong indication that the code in question is trying to do too much in one place and should be broken down into a collection of modules.)