通常当我编写 perl 程序时。我曾经包含以下包。
use strict ;
use warnings ;
use Data::Dumper ;
现在,我想像这样,我不会为每个程序都包含所有这个包。为了那个原因
我会将这些全部打包在我自己的包中。喜欢跟随。
my_packages.pm
package my_packages ;
{
use strict ;
use warnings ;
use Data::Dumper;
}
1;
所以,如果我在 perl 程序中添加 my_packages.pm ,它需要具有以上所有包。
其实我也做过这个实验。但我无法得到这个东西。
这意味着当我使用 my_packages 时。我无法获得“使用严格、使用警告、使用 Data::Dumper ”的功能。
有人帮我解决这个问题......
看一下ToolSet http://search.cpan.org/dist/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
使用工具集:
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!";
/I3az/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)