perl – 如何将我的包导入分组到一个自定义包中?

通常在我编写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,它可以为您完成所有脏的导入工作.

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 /

相关文章

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