通常在我编写perl程序时.我曾经包括以下包.
use strict ;
use warnings ;
use Data::Dumper ;
Run Code Online (Sandbox Code Playgroud)
现在,我想这样,我不会为每个程序包含所有这个包.为此,
我将在我自己的包中包含这些所有包.喜欢以下
my_packages.pm
package my_packages ;
{
use strict ;
use warnings ;
use Data::Dumper;
}
1;
Run Code Online (Sandbox Code Playgroud)
所以,如果我在perl程序中添加my_packages.pm,它需要拥有以上所有的包.
其实我做过这个实验.但我无法得到这些东西.这意味着当我使用my_packages时.我无法获得"使用严格,使用警告,使用Data :: Dumper"的功能.
有人帮我解决了这个问题.....
看看ToolSet,哪个脏导入工作对你有用.
pod中的用法示例:
创建工具集:
# My/Tools.pm
package My::Tools;
use base 'ToolSet';
ToolSet->use_pragma( 'strict' );
ToolSet->use_pragma( 'warnings' );
ToolSet->use_pragma( qw/feature say switch/ ); # perl 5.10
# define exports from other modules
ToolSet->export(
'Carp' => undef, # get the defaults
'Scalar::Util' => 'refaddr', # or a specific list
);
# define exports from this module
our @EXPORT = qw( shout );
sub shout { print uc shift };
1; # modules must return true
Run Code Online (Sandbox Code Playgroud)
使用工具集:
use My::Tools;
# strict is on
# warnings are on
# Carp and refaddr are imported
carp "We can carp!";
print refaddr [];
shout "We can shout, too!";
Run Code Online (Sandbox Code Playgroud)
/ I3az /
| 归档时间: |
|
| 查看次数: |
291 次 |
| 最近记录: |