有没有办法“使用”一个单独的文件,反过来又使用Perl中的其他多个文件?

我想创建几个将被用于我项目中几乎所有脚本和模块的模块.这些可以在我的每个脚本中使用,如:
#!/usr/bin/perl

use Foo::Bar;
use Foo::Baz;
use Foo::Qux;
use Foo::Quux;

# Potentially many more.

可以将所有这些使用语句移动到新的模块Foo :: Corge,然后只需在我的每个脚本和模块中使用Foo :: Corge?

解决方法

这样的事情应该有效:

http://mail.pm.org/pipermail/chicago-talk/2008-March/004829.html

基本上,创建包含许多模块的包:

package Lots::Of::Modules;
use strict; # strictly optional,really

# These are the modules we want everywhere we say "use Lots::Of::Modules".
# Any exports are re-imported to the module that says "use Lots::Of::Modules"
use Carp qw/confess cluck/;
use Path::Class qw/file dir/;
...

sub import {
    my $caller = caller;
    my $class  = shift;

    no strict;
    *{ $caller. '::'. $_ } = \*{ $class. '::'. $_ }
       for grep { !/(?:BEGIN|import)/ } keys %{ $class. '::' };
}

然后在其他地方使用Lots :: Of :: Modules

use Lots::Of::Modules;
confess 'OH NOES';

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...